You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2003/09/23 20:09:31 UTC

DO NOT REPLY [Bug 23360] New: - XMLGrammarPreparser errors when resolving external entities

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23360>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23360

XMLGrammarPreparser errors when resolving external entities

           Summary: XMLGrammarPreparser errors when resolving external
                    entities
           Product: Xerces2-J
           Version: 2.5.0
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Other
        AssignedTo: xerces-j-dev@xml.apache.org
        ReportedBy: hmiller@eti.com


I've search Bugzilla for all that might relate to this problem and reviewed
email for related issues. None really describe the problem and only a few
address a fix in CVS (but only fixes part of the problem). To that end, I'm
submitting this bug report...

The XMLGrammarPreparser class is not gathering external entity data for DTDs
requiring it. At first I thought it was because I wasn't seting the proper
features, but that doesn't seem to be the case either. it appears that the
preparser is ignoring the feature settings, particularly the "load-external-dtd"
feature. I have sample code and data below...

I am using Xerces2-J 2.5.0 on SuSE Linux 8.2, but the exact same problem also
exists using Xerces2-J 2.4.0 on Solaris (SunOS 5.7).

I'm setting he features within my preparser object, but they are definitely
being ignored when it runs -- I've even misspelled them purposely just to see if
the code would complain. Same errors as before resulted, so essentially
*nothing* happened. Now I'm convinced there's a problem.

Much of my code is borrowed from the XMLGrammarBuilder.java sample program. In
fact, the XMLGrammarBuilder can be used to show this problem. My test code is as
follows:

   SymbolTable sym = new SymbolTable(BIG_PRIME);
   XMLGrammarPreparser preparser = new XMLGrammarPreparser(sym);
   XMLGrammarPoolImpl grammarPool = new XMLGrammarPoolImpl();

   if(isDTD) {
      XMLDTDLoader grammarLoader = new XMLDTDLoader(sym, grammarPool);
      preparser.registerPreparser(XMLGrammarDescription.XML_DTD, grammarLoader);
   } else {
      preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
   }

   preparser.setGrammarPool(grammarPool);
   preparser.setProperty(GRAMMAR_POOL, grammarPool);
   preparser.setProperty(SYMBOL_TABLE, sym);

   preparser.setFeature(NAMESPACES_FEATURE_ID, true);
   preparser.setFeature(VALIDATION_FEATURE_ID, false);
   preparser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, false);

   // Set these to see if preparser will listen to them:
  
preparser.setFeature("http://xml.org/sax/features/external-parameter-entities",
true);
  
preparser.setFeature("http://apache.org/xml/features/continue-after-fatal-error",
true);
   preparser.setFeature("http://apache.org/xml/nonvalidating/load-dtd-grammar",
true);
   preparser.setFeature("http://apache.org/xml/nonvalidating/load-external-dtd",
true);

   // parse the grammar...
   Grammar g = null;
   try {
      if (isDTD) {
        // Process DTD input file
        g = preparser.preparseGrammar(XMLGrammarDescription.XML_DTD,
                                    stringToXIS(inputFile) );       
      } else {
        // Process schema input file
        g = preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA,
                                      stringToXIS(inputFile) );
      }
      :
      ...and so on...
      :

The failing input DTD file looks like:

<?xml version='1.0' encoding='UTF-8' ?>
<!ENTITY % entDec SYSTEM "EntityDecl.dtd" >
%entDec;

<!ELEMENT nameList (name, alias?)+>
  <!ELEMENT name (%flName;) >
  <!ELEMENT alias (%flName;) >
  
My external entity file (EntityDecl.dtd) looks like:

<?xml version='1.0' encoding='UTF-8' ?>
<!ENTITY % flName " firstName, lastName " >
   <!ELEMENT firstName (#PCDATA) >
   <!ELEMENT lastName (#PCDATA) >

The problem is with DTD being read in the preparser. I get the following message
returned when I run the Java program:

[Error] :-1:-1: http://www.w3.org/TR/1998/REC-xml-19980210#EntityNotDeclared?flName
[Fatal Error] :-1:-1:
http://www.w3.org/TR/1998/REC-xml-19980210#MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN?name

Error found during parsing:
http://www.w3.org/TR/1998/REC-xml-19980210#MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN?name

Stack Trace:
:::::-1:-1:http://www.w3.org/TR/1998/REC-xml-19980210#MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN?name
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
        at org.apache.xerces.impl.XMLDTDScannerImpl.scanChildren(Unknown Source)
        at org.apache.xerces.impl.XMLDTDScannerImpl.scanElementDecl(Unknown Source)
        at org.apache.xerces.impl.XMLDTDScannerImpl.scanDecls(Unknown Source)
        at
org.apache.xerces.impl.XMLDTDScannerImpl.scanDTDExternalSubset(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDLoader.loadGrammar(Unknown Source)
        at org.apache.xerces.parsers.XMLGrammarPreparser.preparseGrammar(Unknown
Source)
        at com.eti.rs.xml.XMLParser.main(Unknown Source)

Clearly, the preparser stopped before any of my code resumes. I'm setting
everything I know to set up before the preparse call.

Only when I move the ENTITY declaration to within my input DTD file, does it
parse and gather all the DTD info I need to process (the following DTD works
against the same Java code):

<?xml version='1.0' encoding='UTF-8' ?>
<!ENTITY % flName " firstName, lastName " >
   <!ELEMENT firstName (#PCDATA) >
   <!ELEMENT lastName (#PCDATA) >

<!ELEMENT nameList (name, alias?)+ >
  <!ELEMENT name (%flName;) >
  <!ELEMENT alias (%flName;) >

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org