Quick test professional

QTP Tips QTP codes QTP Faqs and more

Create XML using Dotnet Factory

 Dim objWriter,XmlWriter
   Set objWriter = DotNetFactory.CreateInstance(“System.Xml.XmlWriter”, “System.Xml”)’ Creates the instance for the XMLWriter
 set XmlWriter=objWriter.Create(“C:\Documents and Settings\kmohankumar\Desktop\1234.xml”)’ creates xml document
 
 XmlWriter.WriteStartElement(“Books”)’ start writing the element
 XmlWriter.WriteStartElement(“Author”)

XmlWriter.WriteAttributeString “Name”, “Mohan”‘ writes  attributes and its values to the element
 XmlWriter.WriteEndElement()’ ends writing the element
 XmlWriter.WriteStartElement(“Title”)

XmlWriter.WriteAttributeString “Title1”, “QTP”‘
 XmlWriter.WriteEndElement()
 XmlWriter.WriteFullEndElement()

XmlWriter.close()

Set objWriter =Nothing

Author:Mohan kakarla

November 27, 2008 - Posted by | DotNetFactory, XML Scripting

3 Comments »

  1. Hi Mohan,

    You have really done a great job out here. Really helpful to QTP professionals. I shall recommend it to scores of QTP people out here.

    Comment by Abhilash Gopi | October 26, 2009 | Reply

  2. Hi Mohan,
    I have a question with regards to this code. When i try creating the xml document, i get an error in QTP saying: “Object doesn’t support this property or method: ‘Create'”
    My code so far:
    Set myXmlWriter = DotNetFactory.CreateInstance(“System.Xml.XmlWriter”, “System.Xml”)
    Set newXmlScript = myXmlWriter.Create(“C:\test.xml”)

    Thank you for your help!

    Comment by calvin | July 23, 2010 | Reply

  3. Hello Mohan Kumar Kakarla – Your website is very helpful. I am trying to do the following. Can you please tell me if this can be done, if so how

    1. I want to use DotNetFactory and use TreeView Object and
    display all the Nodes from a XML file below is the example

    + Feature one
    + Child Feature one
    + Child Feature two
    + Feature one
    + Child Feature one
    + Child Feature two

    Comment by Shan Bollapragada | July 27, 2010 | Reply


Leave a comment