Welcome! Log In Create A New Profile

Advanced

[WD12] XMLFind

Posted by Louis Verbraak 
Louis Verbraak
[WD12] XMLFind
July 02, 2009 11:34AM
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.
DerekT
Re: [WD12] XMLFind
July 02, 2009 07:13PM
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
Louis Verbraak
Re: [WD12] XMLFind
July 02, 2009 07:20PM
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.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: