Create XML (Dotnet Factory)

Share this post
FaceBook  Twitter  Mixx.mn     


To creates xml document, use following code:
Step:
1) Create a XML Instance using DotNetFactory

2) creates xml document

3) start writing the element

4) writes  attributes and its values to the element

5) ends writing the element

6) Write as many Element you want

7) Close the XMl


Code:



 Dim objWriter,XmlWriter
 
 '1) Create a XML Instance using DotNetFactory
 Set objWriter = DotNetFactory.CreateInstance("System.Xml.XmlWriter", "System.Xml") '’ Creates the instance for the XMLWriter
 
 '2) creates xml document
 set XmlWriter=objWriter.Create("C:\......\abc.xml") ' creates xml document

'3) start writing the element
 XmlWriter.WriteStartElement("Books") '’ start writing the element
 XmlWriter.WriteStartElement("Author")

 '4) writes  attributes and its values to the element
 XmlWriter.WriteAttributeString "Name", "Ritesh"' writes  attributes and its values to the element
 
 '5) ends writing the element
 XmlWriter.WriteEndElement() ' ends writing the element
 
'6) Write as many Element you want  
 XmlWriter.WriteStartElement("Title")

 XmlWriter.WriteAttributeString "Title1", "QTP"'
 XmlWriter.WriteEndElement()
 XmlWriter.WriteFullEndElement()

 '7) Close the XMl
  XmlWriter.close()

Set objWriter =Nothing