JasperReports uses the SAX 2.0 API to parse the XML files. However, it is not tied to a particular SAX 2.0 implementation, like Xerces for examples, but instead you are able to decide at runtime what XML parser you are using.
To instantiate the parser class, JasperReports uses the createXMLReader() method of the XMLReaderFactory class.
In this case, it will be necessary at runtime to set the org.xml.sax.driver Java system property to the full class name of the SAX driver, as specified in the SAX 2.0 documentation.
You can achieve this in two ways. We shall explain both using the Xerces XML parser, just like we do it in the provided samples. If you use a different SAX 2.0 XML parser, you have to modify the name of the parser class accordingly.
The first way you can set a system property is by using the -D switch in the command line when you launch the Java Virtual Machine:
java -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser MySAXApp sample.xml
In all the provided samples we use the Ant build tool to perform different tasks. We supply this system property to the JVM using the <sysproperty> element of the <java> built-in task:
<sysproperty key="org.xml.sax.driver" value="org.apache.xerces.parsers.SAXParser"/>
The second way to set a system property is by using the java.lang.System.setProperty(String key, String value) method like this:
System.setProperty( "org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser" );
Check the jsp/compile.jsp and WEB-INF/classes/servlets/CompileServlet.java files in the /demo/samples/webapp sample provided, to see this in action.