Unified Functional Testing (formerly QTP) News and Support Forum
Showing results for 
Search instead for 
Do you mean 

Unable to get data from XML


Unable to get data from XML

below is th XML


                           <contact isPrimary="true" type="HOME" id="1">
                              <note>Call me after 10am</note>
                           <contact isPrimary="false" type="HOME" id="2">
                              <note>I will be out of station.</note>



using UFT ,I need to get the values of elements "number" and "note" only if parent element  contact isPrimary="true"

please suggest the code for this

Can i do this by considering id ?

How to get the description of parent element ?

Regular Advisor

Re: Unable to get data from XML

MsgBox GetPhoneNumberForPrimaryCusomers("Pass the XML File Name Here)
Public Function GetPhoneNumberForPrimaryCusomers(ByVal XMLFileName)
	Dim iPhoneNumber : iPhoneNumber = -1
	Dim xmlApp : Set xmlApp = CreateObject("Msxml2.DOMDocument")
	Dim xmlNodePath : xmlNodePath = "callInInfo/contact[@isPrimary=""true""]/number"
	xmlApp.load XMLFileName
	If xmlApp.parseError.errorCode = 0 Then
		xmlApp.async = False
		Dim xmlNodeToFind : Set xmlNodeToFind = xmlApp.selectSingleNode(xmlNodePath)		
		If Not xmlNodeToFind Is Nothing Then
			iPhoneNumber = xmlNodeToFind.childNodes(0).nodeValue
			MsgBox iPhoneNumber
		End If
		iPhoneNumber = xmlApp.parseError.errorCode
	End If
	GetPhoneNumberForPrimaryCusomers = iPhoneNumber
End Function



Re: Unable to get data from XML

Pls can u help me with correct hierarchical path because the msgbox is returning -1

Also need the total count of <contact isPrimary="true " type="HOME" id="1">

need the count of how many times type="HOME" with "<contact" tagname in the XML .It can be either ="true" or ="false",that does not matter but the tpye should be "HOME".PFA XML