0

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?

Nish
  • 31
  • 6
  • xml can't contain `&`. Correct xml must have escaped `&` as `&`. If you change it to any symbol or just delete it, your 1st xpath will work. – splash58 Jul 08 '15 at 08:19
  • @splash58: Yes. That does seem the solution as it also works on codebeautify.org. But the problem is I am getting the '&' as part of the Jmeter response itself. I can't really edit the Response(Or can I??). Any idea on how I can extract the value with the '&' there? – Nish Jul 08 '15 at 08:22
  • if yuo use any progamm language, read xml as text, replace `&` with any char and then parse – splash58 Jul 08 '15 at 08:26
  • possible duplicate of [parsing XML with ampersand](http://stackoverflow.com/questions/1473826/parsing-xml-with-ampersand) – splash58 Jul 08 '15 at 08:33
  • any feedback on this ? if answer is OK (which I think it is) it should be accepted so that users know they can rely on answer – UBIK LOAD PACK Jul 09 '15 at 19:53

2 Answers2

1

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>
Community
  • 1
  • 1
UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • +1 Thank you for teaching the OP to fish (interpret error messages) instead of just handing them a fish. – LarsH Jul 08 '15 at 13:33
1

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.

Zach Young
  • 10,137
  • 4
  • 32
  • 53
Nish
  • 31
  • 6
  • The path i used was //Cost. I first extracted that using Xpath Extractor in Jmeter & then stored that as a User Defined variable on jmeter. That gave me freedom to use the Cost variable anywhere i want. – Nish Jul 20 '15 at 06:24