Nish
Nish

Reputation: 31

Extracting path from xml

I am trying to extract a particular Xpath from a returned XML response on Jmeter.

Sample Response XML:

<?xml version="1.0" encoding="UTF-8"?>
<Responses>
<Rate href="http://test.com/psi?attribute1=x&attribute2=y">
<Cost currency='USD'>10</Cost>
</Rate>
</Responses>

I am using http://codebeautify.org/Xpath-Tester# to obtain the XPATH. I need the cost "10". I am looking at Xpath - //Responses/Rate/Cost/text() but this returns blank value. Now I update my XML to (Note: Removed the href part):

<?xml version="1.0" encoding="UTF-8"?>
<Responses>
<Rate>
<Cost currency='USD'>10</Cost>
</Rate>
</Responses>

The same XPATH //Responses/Rate/Cost/text() now returns "Text = 10". Any idea what problem the href is causing?

Upvotes: 0

Views: 768

Answers (2)

Nish
Nish

Reputation: 31

Thanks all for the suggestions. The issue was with the framing of XPATH. There were multiple problems:

  1. I had no control over the response XML
  2. http://codebeautify.org/xmlviewer didn't work for me: I tried altering my xpath's but didnt get back any results.
  3. http://www.freeformatter.com/xpath-tester.html worked better: not only did it validate my XML, it also gave me freedom to alter my xpath before actually using it in jmeter

All in all, problem was wrong XPATH. Lesson learnt: Always check the xpath on freeformatter (or any other similar tool) before actually feeding into jmeter.

Upvotes: 1

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34566

I tried your xml and JMeter gives me:

Assertion failure message: The reference to entity "attribute2" must end with the ';' delimiter. See log file for further details.

And log contains:

2015/07/08 10:46:26 ERROR - jmeter.util.XPathUtil: Type=Val=false Tol=false org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 107; The reference to entity "attribute2" must end with the ';' delimiter.

2015/07/08 10:46:26 WARN - jmeter.extractor.XPathExtractor: SAXException while processing (//Responses/Rate/Cost/) The reference to entity "attribute2" must end with the ';' delimiter.

So you issue is due to wrong XML, you should have:

 <?xml version="1.0" encoding="UTF-8"?>
 <Responses>
 <Rate href="http://test.com/psi?attribute1=x&amp;attribute2=y">
 <Cost currency='USD'>10</Cost>
 </Rate>
 </Responses>

Upvotes: 1

Related Questions