Micro Focus QTP (UFT) Forums
Script to read a XML file - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Script to read a XML file (/Thread-Script-to-read-a-XML-file)



Script to read a XML file - Anand - 05-19-2011

Hi all,

I am new to VBScripting. i want to read XML file to itereate through all tag names, Tag Values,Attribute Names and Attribute Value.

I have attached the sample XML

Please anyone can help me with the code.

Regards,
Anand


RE: Script to read a XML file - suresh vasu - 05-19-2011

Anand,

Please go through the below link, hopefully that will solve your problem.

http://motevich.blogspot.com/2008/09/how-to-read-xml-file-from-qtp_08.html


RE: Script to read a XML file - deepaksporty - 05-19-2011

Hi Anand,

Please go through XMLDOM Object model...you can google it "vbscript+XMLDOM" and go through the methods and properties which XML DOM provides. You'll also get some examples/sample code which'll help you to better understand the concept.


RE: Script to read a XML file - Anand - 05-24-2011

I got the code for retriving node values but i was not able to find the code for retriving attribute value.

i want to get the value of attribute "ref" in the below xml:
---------------------------------------------

Code:
<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

VBScript:

Code:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("states.xml")

Dim objChildNodes, strNode
Set objChildNodes = objXMLDoc.documentElement.childNodes<State>

For Each strNode In objChildNodes
   document.write(strNode.nodeName & "<br>")
Next



RE: Script to read a XML file - Anand - 05-30-2011

@suresh vasu : The link provided by you also doesnt gives info of how to get the values of attribute