Unified Functional Testing Practitioners Forum
cancel

Unable to get data from XML

Neeta_D
Occasional Advisor

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 ?

2 REPLIES
Ryoganat1
Collector

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

 

Highlighted
Neeta_D
Occasional Advisor

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

//Add this to "OnDomLoad" event