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/11/13 02:19:03 UTC

DO NOT REPLY [Bug 24669] New: - Internal entities added via addInternalEntity() are lost

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=24669>.
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=24669

Internal entities added via addInternalEntity() are lost

           Summary: Internal entities added via addInternalEntity() are lost
           Product: Xerces2-J
           Version: 2.4.0
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Other
        AssignedTo: xerces-j-dev@xml.apache.org
        ReportedBy: laraj@wellsfargo.com


Hi,
We're processing xml documents that contain entity names such as &pound;, &yen; 
etc.  We tried getting a reference to the XMLEntityManager via the 
property: "http://apache.org/xml/properties/internal/entity-manager".  
Once we have the reference, we invoke its method addInternalEntity() and load 
all the entities we want to handle.  The issue is that when we invoke the 
parse() method on the DOMParser object, the newly added internal entities are 
cleared by the call to reset() all the way in BasicParserConfiguration.java 
file, when it resets the components.  Also noticed a new XMLEntityManager is 
instantiated during the execution of the parse() method.  I have included a 
test case and test code.  We have worked around it by loading them in the reset
() method after the fEntities.clear(); is done.  I also tried this with 2.5.0 
and have the same issue.

Regards,
Julio Lara

import java.io.*;

import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;
import org.apache.xerces.impl.XMLEntityManager;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;

public class TestXMLEntityManager {

    public static void main(String[] args)
        throws FileNotFoundException, SAXNotRecognizedException,
               SAXNotSupportedException, IOException, SAXException
    {
      Reader xmlReader = new FileReader(args[0]);
      String xsdFile = args[1];
      String namespace = null;

      // clean Windows path separator,
      if (null != xsdFile)
        xsdFile = xsdFile.replace('\\', '/');

      if (3 == args.length)
        namespace = args[2];

      DOMParser parser = null;
      SymbolTable symbolTable = null;
      CachingGrammarPool grammarPool = new CachingGrammarPool();

      parser = new DOMParser(symbolTable, grammarPool);

      // set features.
      parser.setFeature("http://xml.org/sax/features/namespaces", true);
      parser.setFeature("http://xml.org/sax/features/validation", true);
      parser.setFeature("http://apache.org/xml/features/validation/schema", 
true);
      parser.setFeature("http://apache.org/xml/features/validation/schema-full-
checking", true);


      if ((xsdFile != null) && (! xsdFile.equals("")))
      {
          // determine which property to set for schema location
          if ((namespace != null) && (! namespace.equals("")))
              // case: namespace specified
              parser.setProperty(SCHEMA_WITH_NAMESPACE_LOCATION_PROPERTY,
                                 namespace
                                 + " "
                                 + xsdFile);
          else   // case: no namespace
              parser.setProperty(TestXMLEntityManager.SCHEMA_LOCATION_PROPERTY, 
xsdFile);
      }

      // get entity manager
      XMLEntityManager mgr = (XMLEntityManager)
        parser.getProperty("http://apache.org/xml/properties/internal/entity-
manager");

      mgr.addInternalEntity("yen", "&#165;");

      parser.parse(new InputSource(xmlReader));

    }

    // constants.
    public final static String SCHEMA_LOCATION_PROPERTY =
            org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX +
            org.apache.xerces.impl.Constants.SCHEMA_NONS_LOCATION;

    public final static String SCHEMA_WITH_NAMESPACE_LOCATION_PROPERTY =
            org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX +
            org.apache.xerces.impl.Constants.SCHEMA_LOCATION;

}

schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ice.wellsfargo.com/ifxlite" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:ifxlite="http://ice.wellsfargo.com/ifxlite" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="PingRq">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="ifxlite:Msg"/>
			</xs:sequence>
			<xs:attribute name="sourceId" type="xs:string" 
use="required"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="PingRs">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="ifxlite:Msg" minOccurs="0"/>
			</xs:sequence>
			<xs:attribute name="errorCode" use="required">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:enumeration value="OK"/>
						<xs:enumeration value="ERROR"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:attribute>
			<xs:attribute name="sourceId" type="xs:string" 
use="required"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="Msg">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:minLength value="1"/>
				<xs:maxLength value="37"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="IFX">
		<xs:annotation>
			<xs:documentation>Root of ping request 
response</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:choice>
				<xs:element ref="ifxlite:PingRq"/>
				<xs:element ref="ifxlite:PingRs"/>
			</xs:choice>
		</xs:complexType>
	</xs:element>
</xs:schema>

XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="D:\DEVROOT\xml\ping\ping-
internalrep.xsl"?>
<IFX xmlns="http://ice.wellsfargo.com/ifxlite">
	<PingRq sourceId="ICE">
		<Msg>Test Ping MU &yen; test </Msg>
	</PingRq>
</IFX>

error message:
[Fatal Error] :8:26: The entity "yen" was referenced, but not declared.

Hit uncaught exception org.xml.sax.SAXParseException
org.xml.sax.SAXParseException: The entity "yen" was referenced, but not 
declared.

	at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:263)

	at com.wellsfargo.ice.utils.TestXMLEntityManager.main
(TestXMLEntityManager.java:62)

Exception in thread "main"

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