Friday, January 29, 2010

How to find the total number of child elements.

XMLUtil-1: How to find the total number of child elements.

Below is the XML file used for this example:



To find the total number of Child Elements
Set xmldoc=XMLUtil.CreateXML()
xmldoc.loadfile "c:\blog.xml"
Set root = xmldoc.GetRootElement() ‘Returns the root element
temp=root.ChildElements().count  ‘counting child elements of root
msgbox(temp)




CreateXML Method
Creates and returns an object of type XMLData. If a root name is specified, a new document is created containing the specified root tag.

Syntax
XMLUtil.CreateXML ( [RootName] )
RootName is of Type String and is optional.

LoadFile Method
Initializes an XML object using the specified XML file. You can specify an XML file either from your file system or from Quality Center.

Syntax
XMLData.LoadFile (FilePath)
FilePath String The XML string containing the path or URL of the XML file to load. You can enter the relative path also.

Also See:
How to view ALL elements in a message box, one at a time.
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.