The first thing the application must do is to build the source document, in the form of a tree. The simplest approach is to use the sequence:
String systemId = new File(sourceFile).toURL().toString();
DocumentInfo doc = new XPathEvaluator().setSource(
new SAXSource(new InputSource(systemId)));
Alternatively, you can use the JAXP 1.1 interface. For example:
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"net.sf.saxon.om.DocumentBuilderFactoryImpl");
DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
String systemId = new File(sourceFile).toURL().toString();
Node doc = docBuilder.parse(new InputSource(systemId));
You can define the parser to be used by supplying a parser within the SAXSource
object
supplied to the Builder.build()
method. If you don't supply a parser, Saxon will select one
using the JAXP mechanisms, specifically, the system property javax.xml.parsers.DocumentBuilderFactory
.
If you want to use different parsers depending on the URI of the document being read,
you can achieve this by writing a URIResolver
that nominates the parser to be used for each
input file.