Re: Unable to get data from XML (227 Views)
Reply
Contributor
Neeta_D
Posts: 10
Registered: ‎07-08-2013
Message 1 of 3 (253 Views)

Unable to get data from XML

below is th XML

 

<callInInfo>
                           <contact isPrimary="true" type="HOME" id="1">
                              <number>847-859-9658</number>
                              <note>Call me after 10am</note>
                           </contact>
                           <contact isPrimary="false" type="HOME" id="2">
                              <number>778-874-8745</number>
                              <note>I will be out of station.</note>
                           </contact>

  </callInInfo>

 

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
Ryoganat1
Posts: 90
Registered: ‎10-04-2012
Message 2 of 3 (234 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
	Else
		iPhoneNumber = xmlApp.parseError.errorCode
	End If
	GetPhoneNumberForPrimaryCusomers = iPhoneNumber
End Function

 

Contributor
Neeta_D
Posts: 10
Registered: ‎07-08-2013
Message 3 of 3 (227 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.