Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
3
Erster Beitrag:
vor 8 Jahren, 2 Monaten
Letzter Beitrag:
vor 8 Jahren, 2 Monaten
Beteiligte Autoren:
Louis Verbraak, DerekT

[WD12] XMLFind

Startbeitrag von Louis Verbraak am 02.07.2009 09:34

Hello to you all,

I'm trying to find the logic of the XMLFind statement. I made a xml-file which looks like this:
Quote
<myXMLFile>
__<header>
____<field11>Value11</field11>
____<field12>Value12</field12>
__</header>
__<secondPart>
____<field21>Value21</field21>
____<field22>Value22</field22>
__</secondPart>
</myXMLFile>



Now I want to find the <field22>-tag but I can't see how this should be done. I've tried the XMLFind-statement but I didn't find the tag I was looking for, only when I was at the right level at the right parent-tag.
XMLRoot(myXMLDocument)
XMLFind(myXMLDocument,"field22",XMLElement+XMLContinue,XMLIgnoreCase)


I can use something like this:
Quote
XMLRoot(myXMLDocument)
XMLFirst(myXMLDocument)
XMLChild(myXMLDocument)
WHILE NOT XMLOut(myXMLDocument)
____IF XMLElementName(myXMLDocument)~="secondPart" THEN
________XMLChild(myXMLDocument)
________WHILE NOT XMLOut(myXMLDocument)
____________IF XMLElementName(myXMLDocument))~="field22" THEN
________________// Found what I sought!
____________END
____________XMLNext(myXMLDocument)
________END
________XMLParent(myXMLDocument)
____END
____XMLNext(myXMLDocument)
END



But I thought there is an easier way. Can anybody tell me what way is the best.

Antworten:

Louis

As XML reads tend to be sequential your saecond option is quite commonly the method to use.

If however you are searching for a known value then you need to specify the level required - XMLChildItem.

This code will work on your test file....


lsRes is string
lsXMLDoc is string

lsXMLDoc = fLoadText("c:\bucket\LouisTest.xml")

XMLDocument("XML_Louis",lsXMLDoc)
XMLRoot("XML_Louis")
XMLFind("XML_Louis","Field22",XMLTag+XMLContinue+XMLChildItem,XMLExact)
WHILE XMLFound("XML_Louis")
lsRes = XMLElementName("XML_Louis") + " " + XMLData("XML_Louis")
XMLNext("XML_Louis")
END

XMLClose("XML_Louis")



XMLRoot("XMLConfig") in this case is optional as is the WHILE, XMLNext loop.

HTH, Regards

DerekT

von DerekT - am 02.07.2009 17:13
Hello Derek,

Thanks for your answer. I'd tried something like you describe

'XMLFind("XML_Louis","Field22",XMLTag+XMLContinue+XMLChildItem,XMLExact)'

and used then XMLOut() and XMLFound() and they gave True and False. I'll try once more next week, because I leave for a long weekend now.

Thanks again.

von Louis Verbraak - am 02.07.2009 17:20
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.