Javadoc for org.w3c.dom.Entityclaims:
XML does not require a non-validating XML processor to read and process entity declarations made in an external subset or declared in parameter objects. This means that the analyzed objects declared in an external subset should not be extended by some application classes and that the text of the replacement object may not be available. When replacement text is available , the corresponding Entity node child list represents the structure of this replacement value. Otherwise, the list of children is empty.
Although it does not apply to entity declarations made in an internal subset, must there be some kind of parser configuration that will read and process entity declarations in any subset? In fact, my reading of the documentation suggests that this is the default value.
In any case, I tested the following approach (using Xerces) for objects that were declared in the internal subset (as shown), as well as in the external subset, but foo.hasChildNodes()return false (and foo.getChildNodes()return foo!) In each case:
// some trivial example XML
String xml = "<!DOCTYPE example [ <!ENTITY foo 'bar'> ]>\n<example/>";
InputStream is = new ByteArrayInputStream(xml.getBytes());
// parse
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DocumentType docType = builder.parse(is).getDoctype();
// retrieve the entity - works fine
Entity foo = (Entity) docType.getEntities().getNamedItem("foo");
// now how to get the entity replacement text?
No doubt I am missing something pretty obvious; grateful for your thoughts.
EDIT
As you can see from the answers, my implementation of Xerces is wrong. I will try to upgrade all Xerces libraries to the latest versions, and if this solves my problem, I will close the question. Many thanks.
UPDATE
Xerces , , ; , node . , . , - , , / , .