You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Jeff Turner <je...@socialchange.net.au> on 2001/10/20 13:41:00 UTC

Crimson: 'Attribute "xmlns" is not declared' bug?

Hi,

(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 [
<!ELEMENT foo (#PCDATA)>
]>
<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?

thanks,

--Jeff


-------- 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
        dbf.setValidating(true);
        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 [
<!ELEMENT foo (#PCDATA)>
]>
<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


Re: Crimson: 'Attribute "xmlns" is not declared' bug?

Posted by Edwin Goei <ed...@sun.com>.
Jeff Turner wrote:
> 
> 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 [
> <!ELEMENT foo (#PCDATA)>
> ]>
> <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?

Turning on validation performs DTD validation which does not know
anything about namespaces.  In your DTD, you specify an element "foo"
but no attributes for "foo".  Try adding something like the following to
you DTD:

  <!ATTLIST foo xmlns CDATA #IMPLIED>

Not sure why it would work using Xerces.  Which version?  May be a bug.

-Edwin

---------------------------------------------------------------------
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