<html>
<head>
</head>
<body>
Hello,<br>
<br>
You have it right on for your first statement.<br>
<br>
The last one is also correct in that all child elements of "el1" with no
prefix will belong to the default namespace. <br>
<br>
If there is already a namespace prefix for the element "el1" JDOM should
not attempt to add the default namespace prefix to that element, but only
to child elements. This is a bug,, unless someone else disagrees. Whether
the bug is solely JDOM bug or it's an error in the underlying parser that
surfaces in JDOM, I'm not sure.<br>
<br>
<br>
Kind regards,<br>
<br>
Eric<br>
<br>
<blockquote type="cite" cite="mid:OE2916zGOjEo0TOwk4D0000d61f@hotmail.com">
<meta content="MSHTML 6.00.2600.0" name="GENERATOR">
<style></style>
<div>
<div><font size="2">Hi,</font></div>
<div> </div>
<div><font size="2">I still have one question, just to understand the namespace
spec correctly.</font></div>
<div> </div>
<div><font size="2">If I'm not mistaking, the problem with the original
XML was that the "ns1:el1" element had a default namepsace declaration,
and this collided with the "ns1" prefix.</font></div>
<div><font size="2">The XML spec states that a default namespace applies
to the element where it is declared if that element has no namepsace prefix.
But in this case, the element has a prefix "ns1".</font></div>
<div> </div>
<div><font size="2">So, shouldn't the declared default namespace only apply
to child XML elements of "ns1:el1" which do not have a prefix?</font></div>
<div> </div>
<div><font size="2">Regards,</font></div>
<div> </div>
<div><font size="2">Wouter Cordewiner</font></div>
</div>
<blockquote dir="Ltr" style="padding-right: 0px; padding-left: 5px; margin-left: 5px; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(0,0,0); margin-right: 0px; ">
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; ">
----- Original Message ----- </div>
<div style="background-color: rgb(228,228,228); background-image: none; background-repeat: repeat; background-attachment: scroll; -x-background-x-position: 0%; -x-background-y-position: 0%; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
From:</b><a title="easirois@hotmail.com" href="mailto:easirois@hotmail.com">
Eric A. Sirois</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
To:</b><a title="wcordewiner@hotmail.com" href="mailto:wcordewiner@hotmail.com">
Wouter Cordewiner</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Cc:</b><a title="jdom-interest@jdom.org" href="mailto:jdom-interest@jdom.org">
jdom-interest@jdom.org</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Sent:</b> Wednesday, November 28, 2001 7:24 PM</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Subject:</b> Re: [jdom-interest] JDOM, Xerces and Crimson with namepsaces</div>
<div><br>
</div>
<div><font face="Arial" size="2">Hello,</font></div>
<div> </div>
<div><font face="Arial" size="2">In your example the root element belongs
to the "ns1" namespace, not the no namespace. If you want to have the
root element to belong to the no namespace it cannot have a xmlns attribute
declaration.</font></div>
<div> </div>
<div> </div>
<div><font face="Arial" size="2">XML Namespace rec:</font></div>
<div><font face="Arial" size="2"><!-- snip --></font></div>
<div> </div>
<div><!--StartFragment --><a name="scoping"><font face="Arial">5.1 Namespace
Scoping</font></a>
<p><font face="Arial"><font size="2">The namespace declaration is considered
to apply to the element where it is specified and to all elements within
the content of that element, unless overridden by another namespace declaration
with the same <code><a href="http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NSAttName">
NSAttName</a>
</code> part</font></font></p>
<p><font face="Arial" size="2">Multiple namespace prefixes can be declared
as attributes of a single element</font></p>
</div>
<div><font size="2"><!--StartFragment --><font size="3"><!--StartFragment --><a name="defaulting"><font face="Arial">
5.2 Namespace Defaulting</font></a>
</font>
<p><font face="Arial">A </font><a href="http://www.w3.org/TR/1999/REC-xml-names-19990114/#dt-defaultNS"><font face="Arial">
default namespace</font></a>
<font face="Arial"> is considered to apply to the element where it
is declared (if that element has no </font><a href="http://www.w3.org/TR/1999/REC-xml-names-19990114/#dt-prefix"><font face="Arial">
namespace prefix</font></a>
<font face="Arial">), and to all elements with no prefix within the
content of that element. If the URI reference in a default namespace declaration
is empty, then unprefixed elements in the scope of the declaration are
not considered to be in any namespace. Note that default namespaces do
not apply directly to attributes. </font></p>
</font></div>
<div><font face="Arial" size="2"><!-- snip --></font></div>
<div> </div>
<div><font face="Arial" size="2">From your original note:</font></div>
<div> </div>
<div><font face="Arial" size="2">"When I run the NSTest class using the
Crimson parser, the file gets loaded.<br>
<br>
If I use the Xerces parser, I get following exception:<br>
<br>
org.jdom.JDOMException: Error in building from stream: The namespace<br>
xmlns:=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns">"http://namespace/ns"</a> could not be added as content to "ns1:el1":
The<br>
namespace prefix "" collides with an attribute namespace on the element
"</font></div>
<div> </div>
<div><font face="Arial" size="2">In this case Xerces is right and Crimson
is wrong.</font></div>
<div> </div>
<div><font face="Arial" size="2">"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."</font></div>
<div> </div>
<div><font face="Arial" size="2">True, but only for that element and
any child elements. The namespace will no apply to parent elements. If
you want the root element to belong to the default namespace, it must
declared at the root element.</font></div>
<div> </div>
<div><font face="Arial" size="2">Kind regards,</font></div>
<div> </div>
<div><font face="Arial" size="2">Eric</font></div>
<div> </div>
<div> </div>
<div>----- Original Message ----- </div>
<blockquote dir="Ltr" style="padding-right: 0px; padding-left: 5px; margin-left: 5px; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(0,0,0); margin-right: 0px; ">
<div style="background-color: rgb(228,228,228); background-image: none; background-repeat: repeat; background-attachment: scroll; -x-background-x-position: 0%; -x-background-y-position: 0%; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
From:</b><a title="wcordewiner@hotmail.com" href="mailto:wcordewiner@hotmail.com">
Wouter Cordewiner</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
To:</b><a title="easirois@hotmail.com" href="mailto:easirois@hotmail.com">
Eric A. Sirois</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Cc:</b><a title="jdom-interest@jdom.org" href="mailto:jdom-interest@jdom.org">
jdom-interest@jdom.org</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Sent:</b> Wednesday, November 28, 2001 11:54 AM</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Subject:</b> Re: [jdom-interest] JDOM, Xerces and Crimson with namepsaces</div>
<div><br>
</div>
<div><font face="Arial" size="2">Hi,</font></div>
<div> </div>
<div><font face="Arial" size="2">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.</font></div>
<div><font face="Arial" size="2">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.</font></div>
<div> </div>
<div><font face="Arial" size="2">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.</font></div>
<div> </div>
<div><font face="Arial" size="2">In my humble opinion, it seems like
something is not consistent.</font></div>
<div> </div>
<div><font face="Arial" size="2">Regards,</font></div>
<div> </div>
<div><font face="Arial" size="2">Wouter Cordewiner</font></div>
<blockquote dir="Ltr" style="padding-right: 0px; padding-left: 5px; margin-left: 5px; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(0,0,0); margin-right: 0px; ">
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; ">
----- Original Message ----- </div>
<div style="background-color: rgb(228,228,228); background-image: none; background-repeat: repeat; background-attachment: scroll; -x-background-x-position: 0%; -x-background-y-position: 0%; font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
From:</b><a title="easirois@hotmail.com" href="mailto:easirois@hotmail.com">
Eric A. Sirois</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
To:</b><a title="wcordewiner@hotmail.com" href="mailto:wcordewiner@hotmail.com">
Wouter Cordewiner</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Cc:</b><a title="jdom-interest@jdom.org" href="mailto:jdom-interest@jdom.org">
jdom-interest@jdom.org</a>
</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Sent:</b> Tuesday, November 27, 2001 11:41 PM</div>
<div style="font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; line-height: normal; font-stretch: normal; font-size-adjust: none; "><b>
Subject:</b> Re: [jdom-interest] JDOM, Xerces and Crimson with namepsaces</div>
<div><br>
</div>
<div><!--StartFragment --><font face="Arial" size="2"> Hello,<br>
</font>
<pre wrap=""><font face="Arial" size="2">The example below should work for you. For element "el1" you assigned it the default namespace "<a href="http://namespace/ns">http://namespace/ns</a>" but added the prefix for the ns1 prefix. <br><br>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.<br><br>When you declare/assign a namespace it is associated with the current element and any child element not including attributes.</font></pre>
<pre wrap=""><font face="Arial" size="2"><br><br><br><?xml version="1.0" encoding="UTF-8" ?><br><ns1:root xmlns:ns1=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns1">"http://namespace/ns1"</a>><br> <el1 xmlns=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns">"http://namespace/ns"</a> att1="Attribute 1" /><br></ns1:root></font></pre>
<font face="Arial" size="2">namespace element<br>
ns1 root<br>
default el1<br>
<br>
If you need the XML as-is try<br>
</font>
<pre wrap=""><font face="Arial" size="2"><?xml version="1.0" encoding="UTF-8" ?><br><root xmlns=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns">"http://namespace/ns"</a>><br> <ns1:el1 xmlns:ns1=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns1">"http://namespace/ns1"</a> att1="Attribute 1" /><br></root></font></pre>
<br>
<br>
<font face="Arial" size="2">HTH,<br>
<br>
Eric<br>
<br>
Wouter Cordewiner wrote:<br>
</font>
<blockquote cite="mid:OE12GvelgED05qr36VV0000deca@hotmail.com" type="cite">
<pre wrap=""><font face="Arial" size="2">Hi,<br><br>I encountered an issue that seems to depend on the XML parser I use.<br><br>Below a reproducable (XML file and Java code) to illustrate the issue I<br>encounter:<br><br>File "ns.xml":<br><br><?xml version="1.0" encoding="UTF-8" ?><br><br><root xmlns:ns1=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns1">"http://namespace/ns1"</a>><br><br> <ns1:el1 xmlns=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns">"http://namespace/ns"</a> att1="Attribute 1" /><br><br></root><br><br>Java code:<br><br>public class NSTest {<br> public static void main(String[] args) {<br> try {<br> // Create JDOM tree.<br> org.jdom.input.DOMBuilder db = new org.jdom.input.DOMBuilder();<br> org.jdom.Document doc = db.build ( new java.io.File ( "ns.xml" ) );<br> } catch ( Throwable ex ) {<br> ex.printStackTrace();<br> }<br> }<br> private NSTest() {}<br>}<br><br>When I run the NSTest class us
ing the Crimson parser, the file gets loaded.<br><br>If I use the Xerces parser, I get following exception:<br><br>org.jdom.JDOMException: Error in building from stream: The namespace<br>xmlns:=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns">"http://namespace/ns"</a> could not be added as content to "ns1:el1": The<br>namespace prefix "" collides with an attribute namespace on the element<br> at org.jdom.input.DOMBuilder.build(DOMBuilder.java:279)<br> at org.jdom.input.DOMBuilder.build(DOMBuilder.java:300)<br> at NSTest.main(NSTest.java:7)<br>Root cause: org.jdom.IllegalAddException: The namespace<br>xmlns:=<a class="moz-txt-link-rfc2396E" href="http://namespace/ns">"http://namespace/ns"</a> could not be added as content to "ns1:el1": The<br>namespace prefix "" collides with an attribute namespace on the element<br> at org.jdom.Element.addNamespaceDeclaration(Element.java:391)<br> at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:417)<br> at org.jdom.input.DOM
Builder.buildTree(DOMBuilder.java:459)<br> at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:377)<br> at org.jdom.input.DOMBuilder.build(DOMBuilder.java:262)<br> at org.jdom.input.DOMBuilder.build(DOMBuilder.java:300)<br> at NSTest.main(NSTest.java:7)<br><br>I looked into it, and I think the problem lies in the difference between the<br>Crimson and Xerces parser on the implementation of the NamedNodeMap<br>interface of both parsers.<br>The NamedNodeMap object returned from the getAttributes() method on the<br>ns1:el element is causing the problem.<br>If you call the item(int) method on the NamedNodeMap object, Xerces and<br>Crimson return the attributes in a different order.<br><br>Any ideas/suggestions on how to solve this?<br><br>Thank you,<br><br>Wouter Cordewiner<br>_______________________________________________<br>To control your jdom-interest membership:<br><a class="moz-txt-link-freetext" href="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@
yourhost.com">http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</a><br><br></font></pre>
</blockquote>
<br>
</div>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>