Saxon Issue 'Unexpanded Entity'
Added by Anonymous about 16 years ago
Legacy ID: #5395535 Legacy Poster: Alex Maskovyak (litcigar)
My apologies, but I am somewhat new to the world of Saxon. I am getting the following error: "Exception in thread "main" java.lang.IllegalStateException: Unexpanded entity in DOM4J tree" I'm not exactly certain I understand what this means or how to correct it. I've dug around online and haven't been able to locate an answer. Is this an issue with Saxon or is it an issue with the way I'm reading in an xml document? Any assistance would be appreciated.
Replies (6)
Please register to reply
RE: Saxon Issue 'Unexpanded Entity' - Added by Anonymous about 16 years ago
Legacy ID: #5395597 Legacy Poster: Alex Maskovyak (litcigar)
I realize that this is a little vague. I suppose a little bit more of an explanation is in order. I create a dom4j document like this: SAXReader reader = new SAXReader(); Document document = null; try { document = reader.read( pFile ); } I then go about creating an XPathExpression: XPathEvaluator xpathEvaluator = new XPathEvaluator(); Configuration config = xpathEvaluator.getConfiguration(); DocumentWrapper documentWrapper; XPathExpression xpathExpression; try { documentWrapper = new DocumentWrapper(pDocument, null, config); xpathExpression = xpathEvaluator.compile( ".[@attr='test']" ); } catch (XPathExpressionException e) { e.printStackTrace(); } Later on, when I have an element from the dom4j document, I attempt to evaluate the xpath expression: Element element = document.getRootElement(); String evaluated = xpathExpression.evaluate(documentWrapper.wrap(element)); I get the error that I explained above.
RE: Saxon Issue 'Unexpanded Entity' - Added by Anonymous about 16 years ago
Legacy ID: #5397091 Legacy Poster: Michael Kay (mhkay)
I'm afraid I don't immediately know the answer to this one. The DOM4J interface in Saxon can't handle a DOM4J tree that contains Entity nodes, and fails with this message if it encounters an Entity node. But I'm not sure how to configure DOM4J to avoid creating Entity nodes (which correspond to entity references in the source XML document). You could try calling normalize() on the DOM4J document node after constructing the tree, this may get rid of the Entity nodes, but the specification isn't very clear on the point. Meanwhile I'll drop a note to the author of this code to ask if he can help. Michael Kay http://www.saxonica.com/
RE: Saxon Issue 'Unexpanded Entity' - Added by Anonymous about 16 years ago
Legacy ID: #5400028 Legacy Poster: Alex Maskovyak (litcigar)
Michael, I attempted to use normalize(), but ran into the same issue. Thanks for sending word to the dom4j authors, hopefully they will know more about this issue.
RE: Saxon Issue 'Unexpanded Entity' - Added by Anonymous about 16 years ago
Legacy ID: #5421179 Legacy Poster: Erik Bruchez (ebruchez)
I see the code in the dom4j NodeWrapper that throws the exception. I have never encountered this error. The JDOM wrapper seems to do something similar. Still, I investigated a bit: * I read in the W3C DOM API: "the XML processor may completely expand references to entities while building the Document, instead of providing <code>EntityReference</code> nodes". * dom4j has a SAXContentHandler class which builds a dom4j tree from SAX events, and it creates Entity nodes in response to LexicalHandler.startEntity/LexicalHandler. endEntity. The doc for SAX says: "you can use the http://xml.org/sax/features/lexical-handler/parameter-entities feature to query or control the reporting of parameter entities". So it seems that if you could configure the XML parser with this parameter to avoid creation of Entity nodes. Alternatively, the dom4j NodeWrapper could be modified to handle such nodes, I am just not sure exactly what should be done with them. -Erik
RE: Saxon Issue 'Unexpanded Entity' - Added by Anonymous about 16 years ago
Legacy ID: #5424169 Legacy Poster: Michael Kay (mhkay)
OK, I've dug a little deeper. Saxon can't handle DOM4J trees that contain Entity nodes, so if you're going to use DOM4J as the input to Saxon then you need to construct the tree in such a way that Entity nodes are not created. The way this is done in the Saxon test suite is to use a JAXP identity transformer to construct the tree: TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl(); DocumentResult result = new org.dom4j.io.DocumentResult(); Transformer trans = factory.newTransformer(); Source streamSource = new StreamSource(new File(xml)); trans.transform(streamSource, result); return new net.sf.saxon.dom4j.DocumentWrapper( result.getDocument(), xml, ((TransformerFactoryImpl)factory).getConfiguration()); Hope this helps. The same applies to JDOM, Michael Kay
RE: Saxon Issue 'Unexpanded Entity' - Added by Anonymous almost 16 years ago
Legacy ID: #5568509 Legacy Poster: Alex Maskovyak (litcigar)
FYI, I implemented this code and successfully evaluated the xpath expression.
Please register to reply