You are on page 1of 1

QTPWorld http://www.qtpworld.com/index.php?

cid=86

Login | Search QTPWorld.com

Chapters XML
Upcoming Trainings
How to get the values of the XML tags ?
QTP Interview Questions

VB Script - Part I => Content of "sample.xml" file from which the tag values will retrieved using below code
<catalog>
VB Script - Part II
<book id="bk101">
<author>Gambardella, Matthew</author>
VB Script - Part III
<title>XML Developer's Guide</title>
<genre>Computer</genre>
Working with Files using FSO <price>44.95</price>
<publish_date>2000-10-01</publish_date>
Excel <description>An in-depth look at creating applications
with XML.</description>
Actions </book>
<book id="bk102">
Functions <author>Ralls, Kim</author>
<title>Midnight Rain</title>
Difference between Action and <genre>Fantasy</genre>
Function <price>5.95</price>
<publish_date>2000-12-16</publish_date>
Parameterization <description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
Object Repository of the world.</description>
</book>
Descriptive Programming </catalog>

Regular Expression Code

Error Handling & Recovery 'Create Microsoft.XMLDOM object


Scenario Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
Output Values
'path of XML file
XMLDataFile="D:\sample.xml"
Database Connections
'Load the XML File
Automation Object Model xmlDoc.Load(XMLDataFile)

Synchronization 'Give the XML path of XML tag you want to access and /text() to access the value of tag.
'XML path follows the hierarchy
Environment Variables 'XML path for author tag will start from catalog->book->author
'so the XML path will be /catalog/book/author
XML 'Text() will gie the value of the tag
Set nodes = xmlDoc.SelectNodes("/catalog/book/author/text()")
Outlook Msgbox " total count of Author tag is " & nodes.length
For i = 0 To (nodes.Length - 1)
Reporting Defect Author= nodes(i).NodeValue

Msgbox "The name of Author is " & Author

Next
Contact Us
'To get the description tag value in the XML file

info@qtpworld.com Set nodes = xmlDoc.SelectNodes("/catalog/book/description/text()")


Msgbox " total count of Description tag is " & nodes.length
+91- 9886477710 For i = 0 To (nodes.Length - 1)
Descripton= nodes(i).NodeValue
Msgbox "The Description is < " & Descripton & " > "
Next

Set xmlDoc=nothing

Copyright QTPWorld.com 2013 Home | Demo videos | Students | Training | FAQ's | Feedback | About Us Designed By WebZone

1 of 1 1/29/2016 9:41 AM