Read XML (Dotnet Factory)

Share this post
FaceBook  Twitter  Mixx.mn     

To read a XML file through QuickTest, use following code:

1) Create an Instance of XML Reader using DotNetFactory

2) Open XMl document

3) Read data and report all notetype and name

4) report its stored value

5) Read all attributes and report back in result

6) Close XML document.

 

'1) Create an Instance of XML Reader using DotNetFactory

Set obXML = DotNetFactory.CreateInstance("System.Xml.XmlReader", "System.Xml")

'2) Open XMl document
set XmlReader=obXML.Create("C:\......\abc.xml")

while (XmlReader.Read())


'3) Read data and report all notetype and name
If  XmlReader.NodeType = "XmlDeclaration" or XmlReader.NodeType = "Element"Then
 
    Reporter.ReportEvent micPass, "NodeType:"&XmlReader.NodeType &"  Name :"& XmlReader.Name& " is at Depth:"& XmlReader.Depth,""

'4) report its stored value


    If XmlReader.HasValue Then
        Reporter.ReportEvent micPass, " Value: "& XmlReader.Value,""
    End If

    Reporter.ReportEvent micPass, "Element:"& XmlReader.Name&"  has attribute(s)"&":"& XmlReader.AttributeCount,""

'5) Read all attributes and report back in result
  If XmlReader.AttributeCount > 0 Then

        while  XmlReader.MoveToNextAttribute()
     fn = XmlReader.Name
     ns = XmlReader.NamespaceURI
      Reporter.ReportEvent micPass," Attribute:"&fn &"  Value: "& ns&" Attribute:"& XmlReader.GetAttribute(fn, ns),""
        wend
     End If
End If
wend

'6) Close XML document.
XmlReader.Close()