Saturday, January 30, 2010

XMLUtil - How to create a new XML file.

XMLUtil: How to create a new XML file.

Set doc = XMLUtil.CreateXML( )
CreateDocument: Creates a new, empty XML document with a specified root name.
doc.CreateDocument "Bookstore"
Set root = doc.GetRootElement( ) 'Get the root element
For i= 0 to 1
st="Book - " & i
sa="Author - " & i
root.AddChildElementByName "Book",""
Set node=root.ChildElements()
Set node=node.item(node.count) 'go to the last node added.
node.AddChildElementByName "Name", st ‘create a child XML node
node.AddChildElementByName "Author", sa ‘create a child XML node
doc.SaveFile "c:\data.xml"
next


The above code will create the following XML file:



For more on CreateXML see here.

Also See:
How to find total number of child elements.
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 move/transfer text from XML file to QTP DataTable.
How to compare two XML files.