Friday, January 29, 2010

How to view ALL elements in a message box, one at a time.

XMLUtil-2: How to view ALL elements in a message box, one at a time.

XML file used:

'To view all elements in a msgbox one at a time
Set xmldoc=XMLUtil.CreateXML()
xmldoc.loadfile "c:\blog.xml"
Set chldrn = xmldoc.ChildElementsByPath( "/ bookstore/book")
For i=1 to chldrn.count
msgbox chldrn.item(i)
Next


ChildElementsByPath Property
Returns all of the child elements that reside in the specified path.

Syntax
XMLData.ChildElementsByPath(XMLPath)

Return Value
XMLElementsColl Object (An object representing a collection of XML elements.)

For Loadfile and CreateXML see here.

Results of running the above code:



Above in the third line of code if you change the path from "/ bookstore/book" to "/ bookstore", then you get the whole file in just one message box.

Also See:
How to find total number of child elements.
How to view the VALUE of elements in a message box, one at a time.
How to get the NAME of the root element, get the COUNT of child
elements of root, get COUNT & NAMES of children of any child element of root.

How to create a new XML file.
How to move/transfer text from XML file to QTP DataTable.
How to compare two XML files.