Hi Bartos, Xerces only recently (as of version 2.7.0) became capable of reporting skipped entities, so in the past it wasn't possible to identify skipped entities in the DOM parser to do what you suggest. As far as I know none of the developers thought of this case so the code was never revisited. So this issue doesn't get lost again, could you please open a bug report [1] in JIRA?
Thanks. [1] http://issues.apache.org/jira/browse/XERCESJ Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] László Bartos <[EMAIL PROTECTED]> wrote on 11/21/2005 06:57:36 AM: > Hi, > > I have already posted this question earlier, but without success: > > I have a problem using xerces-2_7_1: I have to print out the > internal subset of XML documents, but the parameter entity refs are > always resolved by DOM parser. If I set the feature http://xml. > org/sax/features/external-parameter-entities to false, then it is > resolved to empty string (so the parameter entity ref disappears). > > To reproduce the problem: > > 1. Save this as an XML document > > <?xml version="1.0" encoding="utf-8"?> > <!DOCTYPE PEtest PUBLIC "-//TEST//DTD PETest XML//EN" "petest.dtd" [ > <!ENTITY % local.ent PUBLIC "-//TEST//DTD PETest Extension XML//EN" > ""> %local.ent; ]> <PETest> <front> </front> <body> </body></PETest> > > 2. Set the feature http://xml.org/sax/features/external-parameter-entities > to false and call the DOM parser. Here is a sample program: > public static void main(String argv[]) { > ParserWrapper parser = null; > // create parser > try { > parser = (ParserWrapper)Class.forName("dom.wrappers. > Xerces").newInstance(); > parser.setFeature("http://xml.org/sax/features/namespaces > ", false); > parser.setFeature("http://xml.org/sax/features/validation > ", false); > parser.setFeature("http://apache. > org/xml/features/nonvalidating/load-external-dtd", false); > parser.setFeature("http://apache. > org/xml/features/validation/schema", false); > parser.setFeature("http://apache. > org/xml/features/validation/dynamic", false); > parser.setFeature("http://apache.org/xml/features/xinclude > ", false); > parser.setFeature("http://xml.org/sax/features/external- > parameter-entities", false); > // parse file > Document document = parser.parse(argv[0]); > System.out.println(document.getDoctype().getInternalSubset()); > } > catch (Exception e) { > e.printStackTrace(System.err); > } > } // main(String[]) > > Result: The getInternalSubset will return > <!ENTITY % local.ent PUBLIC "-//TEST//DTD PETest Extension XML//EN" ""> > which means that the entity ref is resolved to empty string. (If I set > http://xml.org/sax/features/external-parameter-entities to true, > then the parameter entity ref is correctly resolved and returned in > getInternalSubset, however I need the reference without resolving it.) > > I have found that if I add the following code into org.apache. > xerces.parsers.AbstractDOMParser.startParameterEntity(String, > XMLResourceIdentifier, String, Augmentations): > > ... > //append the paremeter entity reference if it was not resolved > if (fInDTD && fInternalSubset != null && ! > fInDTDExternalSubset && augs != null) { > Object skip = augs.getItem(Constants.ENTITY_SKIPPED); > if (skip instanceof Boolean && (Boolean)skip == Boolean.TRUE) { > fInternalSubset.append(name); > fInternalSubset.append(";\n"); > } > } > > then the parameter entity ref is included in the internal subset. > > I'm far to say that I have experience using xerces, so it can > happen, that I use the wrong functions. Can somebody confirm whether > this is a bug or a feature? > > Bartos László > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
