<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<DIV><FONT size=2>Hi,</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>I still have one question, just to understand the namespace
spec correctly.</FONT></DIV>
<DIV><FONT size=2></FONT> </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><FONT size=2></FONT> </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><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Regards,</FONT></DIV>
<DIV><FONT size=2></FONT> </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: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=easirois@hotmail.com href="mailto:easirois@hotmail.com">Eric A.
Sirois</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=wcordewiner@hotmail.com
href="mailto:wcordewiner@hotmail.com">Wouter Cordewiner</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=jdom-interest@jdom.org
href="mailto:jdom-interest@jdom.org">jdom-interest@jdom.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, November 28, 2001 7:24
PM</DIV>
<DIV style="FONT: 10pt arial"><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><FONT face=Arial size=2></FONT> </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><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>XML Namespace rec:</FONT></DIV>
<DIV><FONT face=Arial size=2><!-- snip --></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>From your original note:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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:="http://namespace/ns" could not be added as
content to "ns1:el1": The<BR>namespace prefix "" collides with an attribute
namespace on the element "</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>In this case Xerces is right and Crimson is
wrong.</FONT></DIV>
<DIV><FONT face=Arial size=2></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><FONT face=Arial size=2></FONT> </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><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Kind regards,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Eric</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=wcordewiner@hotmail.com
href="mailto:wcordewiner@hotmail.com">Wouter Cordewiner</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=easirois@hotmail.com
href="mailto:easirois@hotmail.com">Eric A. Sirois</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=jdom-interest@jdom.org
href="mailto:jdom-interest@jdom.org">jdom-interest@jdom.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, November 28, 2001
11:54 AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] JDOM,
Xerces and Crimson with namepsaces</DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT
face=Arial size=2></FONT><FONT face=Arial size=2></FONT><BR></DIV>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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><FONT face=Arial size=2></FONT> </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><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>In my humble opinion, it seems like something
is not consistent.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Regards,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=easirois@hotmail.com href="mailto:easirois@hotmail.com">Eric A.
Sirois</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=wcordewiner@hotmail.com
href="mailto:wcordewiner@hotmail.com">Wouter Cordewiner</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=jdom-interest@jdom.org
href="mailto:jdom-interest@jdom.org">jdom-interest@jdom.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, November 27, 2001
11:41 PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] JDOM,
Xerces and Crimson with namepsaces</DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT
face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT face=Arial
size=2></FONT><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="http://namespace/ns1"><BR> <el1 xmlns="http://namespace/ns" 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="http://namespace/ns"><BR> <ns1:el1 xmlns:ns1="http://namespace/ns1" 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="http://namespace/ns1"><BR><BR> <ns1:el1 xmlns="http://namespace/ns" 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 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:="http://namespace/ns" 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:="http://namespace/ns" 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.DOMBuilder.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>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com<BR><BR></FONT></PRE></BLOCKQUOTE><BR></DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>