You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Dennis Sosnoski <dm...@sosnoski.com> on 2002/02/07 08:55:17 UTC

Entity error

I'm getting an exception thrown running Xerces2 (2.0.0) DOMParser:

[Fatal Error] :2:13: The entity "name" was referenced, but not declared.
org.xml.sax.SAXParseException: The entity "name" was referenced, but not 
declared.
        at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:235)
        at com.sosnoski.xmlbench.BenchXerces2.build(BenchXerces2.java:86)
        at 
com.sosnoski.xmlbench.BenchDocBase.runTimeTest(BenchDocBase.java:353)        
at com.sosnoski.xmlbench.XMLBench.main(XMLBench.java:481)

with this input:

<?xml version="1.0"?>
<!DOCTYPE spec [
<!ENTITY name "xyzzy">
]>
<spec>&name;</spec>

Am I making some kind of subtle error, or is Xerces2 broken for entities 
outside of attribute values?

  - Dennis


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


Re: Entity error

Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Thanks for trying this out. I went back to track the problem in detail 
and found it was occurring not with the original file, but with a copy 
that had gone through a text->DOM->text cycle. The problem is actually 
on the output side, using XMLSerializer. This keeps the entity reference 
but loses the definition with Xerces 2; with Xerces 1 it just 
substitutes the entity text directly.

Xerces 2:
<?xml version="1.0" encoding="UTF-8"?>
<spec>&name;</spec>

Xerces 1:
<?xml version="1.0" encoding="UTF-8"?>
<spec>xyzzy</spec>

Here's the *complete* test program:

import java.io.*;
import java.util.*;

import javax.xml.parsers.*;

import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;

import org.w3c.dom.*;

import org.xml.sax.*;

public class Test
{
    private static DOMParser m_parser;
    private static XMLSerializer m_serializer;
   
    public static void main(String[] argv) {
        if (m_parser == null) {
            m_parser = new DOMParser();
            try {
                m_parser.setFeature
                    ("http://xml.org/sax/features/validation", false);
                m_parser.setFeature
                    
("http://apache.org/xml/features/dom/defer-node-expansion",
                    true);
                m_parser.setFeature
                    ("http://xml.org/sax/features/namespaces", true);
            } catch (Exception ex) {
                ex.printStackTrace(System.err);
                System.exit(0);
            }
        }
        Object doc = null;
        try {
            m_parser.parse(new InputSource(new FileReader("test.xml")));
            doc = m_parser.getDocument();
            m_parser.reset();
            System.out.println("Success reading document!");
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
            System.exit(0);
        }
        if (m_serializer == null) {
            OutputFormat format = new OutputFormat((Document)doc);
            m_serializer = new XMLSerializer(format);
        }
        try {
            m_serializer.reset();
            CharArrayWriter out = new CharArrayWriter();
            m_serializer.setOutputCharStream(out);
            m_serializer.serialize(((Document)doc).getDocumentElement());
            System.out.println(out.toString());
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
            System.exit(0);
        }
    }
}


Andy Clark wrote:

>Dennis Sosnoski wrote:
>
>>Here's the code (with classpath including xmlParserAPIs.jar and
>>xercesImpl.jar):
>>
>
>I'm using your code and I'm still not seeing any problems with
>the Xerces 2.0.0 release. Is there any other information you
>could provide about your environment?
>



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


Re: Entity error

Posted by Andy Clark <an...@apache.org>.
Dennis Sosnoski wrote:
> Here's the code (with classpath including xmlParserAPIs.jar and
> xercesImpl.jar):

I'm using your code and I'm still not seeing any problems with
the Xerces 2.0.0 release. Is there any other information you
could provide about your environment?

-- 
Andy Clark * andyc@apache.org

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


Re: Entity error

Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Andy Clark wrote:

>Dennis Sosnoski wrote:
>
>>I'm getting an exception thrown running Xerces2 (2.0.0) DOMParser:
>>
>
>This is very strange because I tried your document with Xerces
>2.0.0 and I don't see these problems. (I'm using the dom.*
>samples to test it.)
>
>What is the exact invocation code you are using?
>
Here's the code (with classpath including xmlParserAPIs.jar and 
xercesImpl.jar):

        if (m_parser == null) {
            m_parser = new DOMParser();
            try {
                m_parser.setFeature
                    ("http://xml.org/sax/features/validation", false);
                m_parser.setFeature
                    ("http://xml.org/sax/features/namespaces", true);
            } catch (Exception ex) {
                ex.printStackTrace(System.err);
                System.exit(0);
            }
        }
        Object doc = null;
        try {
            m_parser.parse(new InputSource(in));
            doc = m_parser.getDocument();
            m_parser.reset();
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
            System.exit(0);
        }



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


Re: Entity error

Posted by Andy Clark <an...@apache.org>.
Dennis Sosnoski wrote:
> I'm getting an exception thrown running Xerces2 (2.0.0) DOMParser:

This is very strange because I tried your document with Xerces
2.0.0 and I don't see these problems. (I'm using the dom.*
samples to test it.)

What is the exact invocation code you are using?

-- 
Andy Clark * andyc@apache.org

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