xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Turner <j...@socialchange.net.au>
Subject Crimson: 'Attribute "xmlns" is not declared' bug?
Date Sat, 20 Oct 2001 11:41:00 GMT

(yes, I'd consider crimson OT for a general list too, but there isn't a crimson
list and http://xml.apache.org/mail.html says it's okay.)

I have some standard JAXP 1.1 code (listed at the end) that works with Xerces
and fails with Crimson. It seems Crimson doesn't like XML namespaces. If I try
to create a DOM by parsing: 

<!DOCTYPE foo [
<foo xmlns="http://www.foo.com"/>

I'll get an error claiming 'Attribute "xmlns" is not declared for element "foo".'

That makes perfect sense from a pre-namespaces perspective, but shouldn't a
namespace-aware parser be able to handle this?



-------- Broken.java --------
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

public class Broken {
    public static void main(String args[]) throws Exception {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true); // The default is false. See http://xml.apache.org/~edwingo/jaxp-faq.html
        DocumentBuilder db = dbf.newDocumentBuilder();
        //db.setErrorHandler(new StandardErrorHandler());
        Document doc = db.parse(new java.io.File(args.length==0?"foo.xml":args[0]));

-------- foo.xml --------

<!DOCTYPE foo [
<foo xmlns="http://www.foo.com"/>

The error is:
Error parsing entity SYSTEM "file:/home/jeff/tmp/java/jdom/src/java/foo.xml", line 4 : Attribute
"xmlns" is not declared for element "foo".
Exception in thread "main" org.xml.sax.SAXParseException: Attribute "xmlns" is not declared
for element "foo".
        at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
        at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1411)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
        at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:197)
        at UseDOM.main(UseDOM.java:22)

In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org

View raw message