xpath xslt s9api java and a DTD
Added by Anonymous about 16 years ago
Legacy ID: #5402331 Legacy Poster: kendall shaw (queshaw)
I have 2 classes, one which inspects an XML document with XPath 2.0 expressions and another which runs an XSLT transformation. Is there a performance advantage to parsing the XML once and passing an XdmItem to xpath and xslt? If so, I think I need to find a way to pass an XdmNode to my object that does the xpath execution and also to my object that does the xslt transformation. If I wanted to execute an XSLT transformation on an XdmNode, does this do that: xslt.setInitialContextNode(n); // n is an XdmNode and xslt is an XsltTransformer xslt.transform(); or do I have to use setSource()? Also, I get an error about needing to have the same or a compatible Configuration when I try to construct an XdmNode in one object and evaluate it in another object where I've construct an XPathSelector to evaluate the node. For example, I have: // class A Processor p = new Processor(false); DocumentBuilder db = p.newDocumentBuilder(); XdmNode n = db.build(new SAXSource(xrdr, is)); // xrdr is an XMLReader and is is an InputSource // class B Processor p = new Processor(false); XPathCompiler p = s9.newXPathCompiler(); XPathExecutable p = xpc.compile("..."); XPathSelector xpath = xpe.load(); xpath.setContextItem(xdm); // xdm from class A xpath.evaluate(); Is that normal, or have I probably made a mistake somewhere? If it's normal, can I pass an XdmNode around somehow, or do I have to share a Processor between objects, or something else? Also, the XML needs to be validated against a DTD. How can I use an entity resolver (xml catalog) and use DTD validation with a DocumentBuilder? Do I rely on a SAXSource doing that, or is there some other way to set an entity resolver?
Replies (1)
RE: xpath xslt s9api java and a DTD - Added by Anonymous about 16 years ago
Legacy ID: #5402439 Legacy Poster: Michael Kay (mhkay)
(1) Yes, there is a performance advantage in only parsing the document once. Parsing the document and building the tree can often take much longer than running an XPath expression against it, or even a full transformation. (2) Yes, you can use setInitialContextNode(). Using setSource() is just a shortcut that avoids creating a DocumentBuilder, building the document, and then passing it to setInitialContextNode. (3) Yes, all operations against a particular XdmNode must use the same Configuration - which in s9api terms means for most practical purposes they must use the same Processor. (4) You can request DTD validation using DocumentBuilder.setDTDValidation(true). But to set an EntityResolver you will need to create the XMLReader yourself, set its EntityResolver, wrap it into a SAXSource, and supply the SAXSource to the DocumentBuilder.build() method. Michael Kay http://www.saxonica.com/
Please register to reply