1
votes

I am using xpath extractor to retrieve a form attribute value from the response data. However, this response data contains, among other data the String "C&I", and this is causing the following SAXException

jmeter.extractor.XPathExtractor: SAXException while processing (substring-after(//form[@id='headerForm']/@action,'/dashboard.xhtml?')) The reference to entity "I" must end with the ';' delimiter.

I do not have any control over this data since it is being obtained from the database. I tried checking the "Use Tidy(tolerant parser)" option. That results in the following warning/error

ERROR - jmeter.util.XPathUtil: TidyException: line 35 column 31 - Warning: trimming empty <div>

Line 35 of the response is as follows:

`<div style="clear: both;"></div>`

Extracting that attribute value is essential for further processing for me.

2

2 Answers

5
votes

As for everything there is solution, it might be quick and dirty but there is always more solutions to a single problem.

I recommend using jsoup to do the parsing of HTML for you instead of xpath extractor. I'm assuming you're trying to extract the particular forms' action attribute.

Step 1 -> Add jsoup-1.6.3.jar or any other version to your JMETER_HOME\lib

Step 2 -> Add a BeanShell PostProcessor to your Sampler HTTP or any other

Step 3 -> In a Script big box paste this code :

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

String html = prev.getResponseDataAsString(); // get response from your sampler
Document doc = Jsoup.parse(html);
String formAction = doc.select("#headerForm").attr("action");
vars.put("action", formAction);

HTML selectors are jquery based. So it can do pretty nice and neat things. Anyway you should have ${action} variable to use further in your tests.

Update

So you don't get tangled with the code I've created jMeter post processor called Html Extractor here is the github url :

https://github.com/c0mrade/Html-Extractor

1
votes

The stray & in your source document is not legal in XML. From the XML spec (emphasis mine)

The ampersand character (&) and the left angle bracket (<) may appear in their literal form only when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. They are also legal within the literal entity value of an internal entity declaration; see "4.3.2 Well-Formed Parsed Entities". If they are needed elsewhere, they must be escaped using either numeric character references or the strings "&amp;" and "&lt;" respectively.

The parser is interpreting the & as the start of an entity reference, which it expects to end with a semicolon.

Source:

Note that the error you've included is (almost certainly) unrelated. Tidy is merely pointing out that the div contains no content (i.e. it's empty).