XML Schema Assertion uses javax.xml.parsers.DocumentBuilder.parse() method which stops parsing XML file after the first error.
You can work it around by implementing your own ErrorHandler in i.e. Beanshell Assertion
- Add Beanshell Assertion instead of the XML Schema Assertion
Put the following code into the Beanshell Assertion "Script" area:
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(new File("/path/to/your/schema.xsd")));
Validator validator = schema.newValidator();
final List exceptions = new LinkedList();
validator.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
exceptions.add(exception);
}
public void fatalError(SAXParseException exception) throws SAXException {
exceptions.add(exception);
}
public void error(SAXParseException exception) throws SAXException {
exceptions.add(exception);
}
});
StreamSource xmlFile = new StreamSource(new StringReader(SampleResult.getResponseDataAsString()));
validator.validate(xmlFile);
if (exceptions.size() > 0) {
Failure = true;
for (int i = 0; i < exceptions.size(); i++) {
FailureMessage += "Error " + (i + 1) + " : " + exceptions.get(i).getMessage();
FailureMessage += System.getProperty("line.separator");
}
}
Replace /path/to/your/schema.xsd
with the actual path to XSD schema.
Remember that it may NOT return all the errors in case of fatal errors, according to ErrorHandler class JavaDoc:
Note, however, that there is no requirement that the parser continue to report additional errors after a call to fatalError. In other words, a SAX driver class may throw an exception after reporting any fatalError.
See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on using JMeter and Java API in Beanshell Test Elements.