[jdom-interest] JDOM, Xerces and Crimson with namepsaces
Wouter Cordewiner
wcordewiner at hotmail.com
Wed Nov 28 08:54:36 PST 2001
Hi,
with the example you provide below, the root element will belong to the 'ns1' namespace, while in my example the root element belongs to no namespace.
If I'm interpreting the XML spec correctly, you can start declaring a default namespace (one without prefix) anywhere in the XML document. If another one already declared somewhere up the parent tree, it will override it.
Anyway, my test xml example was just to illustrate that when loading the XML through JDOM using the Xerces parser it fails, while using the Crimson it doesn't.
In my humble opinion, it seems like something is not consistent.
Regards,
Wouter Cordewiner
----- Original Message -----
From: Eric A. Sirois
To: Wouter Cordewiner
Cc: jdom-interest at jdom.org
Sent: Tuesday, November 27, 2001 11:41 PM
Subject: Re: [jdom-interest] JDOM, Xerces and Crimson with namepsaces
Hello,
The example below should work for you. For element "el1" you assigned it the default namespace "http://namespace/ns" but added the prefix for the ns1 prefix. The error message you received is correct. It's saying I don't understand the prefix "ns1" for element "el1" you just assigned it with a default namespace.When you declare/assign a namespace it is associated with the current element and any child element not including attributes.
<?xml version="1.0" encoding="UTF-8" ?><ns1:root xmlns:ns1="http://namespace/ns1"> <el1 xmlns="http://namespace/ns" att1="Attribute 1" /></ns1:root>
namespace element
ns1 root
default el1
If you need the XML as-is try
<?xml version="1.0" encoding="UTF-8" ?><root xmlns="http://namespace/ns"> <ns1:el1 xmlns:ns1="http://namespace/ns1" att1="Attribute 1" /></root>
HTH,
Eric
Wouter Cordewiner wrote:
Hi,I encountered an issue that seems to depend on the XML parser I use.Below a reproducable (XML file and Java code) to illustrate the issue Iencounter:File "ns.xml":<?xml version="1.0" encoding="UTF-8" ?><root xmlns:ns1="http://namespace/ns1"> <ns1:el1 xmlns="http://namespace/ns" att1="Attribute 1" /></root>Java code:public class NSTest { public static void main(String[] args) { try { // Create JDOM tree. org.jdom.input.DOMBuilder db = new org.jdom.input.DOMBuilder(); org.jdom.Document doc = db.build ( new java.io.File ( "ns.xml" ) ); } catch ( Throwable ex ) { ex.printStackTrace(); } } private NSTest() {}}When I run the NSTest class using the Crimson parser, the file gets loaded.If I use the Xerces parser, I get following exception:org.jdom.JDOMException: Error in building from stream: The namespacexmlns:="http://namespace/ns" could not be added as content to "ns1:el1": Thenamespace prefix "" collides with an attribute namespace on the element at org.jdom.input.DOMBuilder.build(DOMBuilder.java:279) at org.jdom.input.DOMBuilder.build(DOMBuilder.java:300) at NSTest.main(NSTest.java:7)Root cause: org.jdom.IllegalAddException: The namespacexmlns:="http://namespace/ns" could not be added as content to "ns1:el1": Thenamespace prefix "" collides with an attribute namespace on the element at org.jdom.Element.addNamespaceDeclaration(Element.java:391) at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:417) at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:459) at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:377) at org.jdom.input.DOMBuilder.build(DOMBuilder.java:262) at org.jdom.input.DOMBuilder.build(DOMBuilder.java:300) at NSTest.main(NSTest.java:7)I looked into it, and I think the problem lies in the difference between theCrimson and Xerces parser on the implementation of the NamedNodeMapinterface of both parsers.The NamedNodeMap object returned from the getAttributes() method on thens1:el element is causing the problem.If you call the item(int) method on the NamedNodeMap object, Xerces andCrimson return the attributes in a different order.Any ideas/suggestions on how to solve this?Thank you,Wouter Cordewiner_______________________________________________To control your jdom-interest membership:http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20011128/70f2ad5c/attachment.htm
More information about the jdom-interest
mailing list