Re: Unable to get data from XML (279 Views)
Posts: 10
Registered: ‎07-08-2013
Message 1 of 3 (305 Views)

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
Posts: 90
Registered: ‎10-04-2012
Message 2 of 3 (286 Views)

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


Posts: 10
Registered: ‎07-08-2013
Message 3 of 3 (279 Views)

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

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.