I have a problem using xerces-2_7_1: If have to print out the internal subset of XML documents, but the parameter entity refs are lost by DOM parser:

Here is the code:
 
    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[])
If I set the feature "http://xml.org/sax/features/external-parameter-entities" to true, then the parameter entity is resolved by DOM. However I need the reference without resolving it. Is this a bug or a feature? Is there a better approach/workaround for that?
 
After some debugging 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. 
 
Can somebody confirm whether this is the only solution or there exist some better?
 
Thanks!
 
Laszlo Bartos 

Reply via email to