No subject


Fri Aug 6 17:04:17 PDT 2004


"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 namespace
xmlns:=3D"http://namespace/ns" could not be added as content to =
"ns1:el1": The
namespace prefix "" collides with an attribute namespace on the element =
"

In this case Xerces is right and Crimson is wrong.

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

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.

Kind regards,

Eric


----- Original Message -----=20
  From: Wouter Cordewiner=20
  To: Eric A. Sirois=20
  Cc: jdom-interest at jdom.org=20
  Sent: Wednesday, November 28, 2001 11:54 AM
  Subject: Re: [jdom-interest] JDOM, Xerces and Crimson with namepsaces


  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 -----=20
    From: Eric A. Sirois=20
    To: Wouter Cordewiner=20
    Cc: jdom-interest at jdom.org=20
    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=3D"1.0" encoding=3D"UTF-8" ?><ns1:root =
xmlns:ns1=3D"http://namespace/ns1">  <el1 xmlns=3D"http://namespace/ns" =
att1=3D"Attribute 1" /></ns1:root>
    namespace     element
            ns1             root
           default          el1

    If  you need the  XML as-is try

<?xml version=3D"1.0" encoding=3D"UTF-8" ?><root =
xmlns=3D"http://namespace/ns">  <ns1:el1 =
xmlns:ns1=3D"http://namespace/ns1" att1=3D"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=3D"1.0" encoding=3D"UTF-8" =
?><root xmlns:ns1=3D"http://namespace/ns1">  <ns1:el1 =
xmlns=3D"http://namespace/ns" att1=3D"Attribute 1" /></root>Java =
code:public class NSTest { public static void main(String[] args) {  try =
{   // Create JDOM tree.   org.jdom.input.DOMBuilder db =3D new =
org.jdom.input.DOMBuilder();   org.jdom.Document doc =3D 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:=3D"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:=3D"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/yo=
uraddr at yourhost.com



------=_NextPart_000_0046_01C1780F.F8DDE9E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2479.6" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>In your example the root element =
belongs to the=20
"ns1" namespace, not the&nbsp;no namespace. If you want to have the root =
element=20
to belong to the no namespace it cannot have a xmlns attribute=20
declaration.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>XML Namespace rec:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&lt;!-- snip --&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><!--StartFragment --><A name=3Dscoping><FONT face=3DArial>5.1 =
Namespace=20
Scoping</FONT></A>
<P><FONT face=3DArial><FONT size=3D2>The namespace declaration is =
considered to=20
apply to the element where it is specified and to all elements within =
the=20
content of that element, unless overridden by another namespace =
declaration with=20
the same <CODE><A=20
href=3D"http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NSAttName">N=
SAttName</A></CODE>=20
part</FONT></FONT></P>
<P><FONT face=3DArial size=3D2>Multiple namespace prefixes can be =
declared as=20
attributes of a single element</FONT></P></DIV>
<DIV><FONT size=3D2><!--StartFragment --><FONT =
size=3D3><!--StartFragment --><A=20
name=3Ddefaulting><FONT face=3DArial>5.2 Namespace =
Defaulting</FONT></A></FONT>
<P><FONT face=3DArial>A </FONT><A=20
href=3D"http://www.w3.org/TR/1999/REC-xml-names-19990114/#dt-defaultNS"><=
FONT=20
face=3DArial>default namespace</FONT></A><FONT face=3DArial> is =
considered to apply=20
to the element where it is declared (if that element has no </FONT><A=20
href=3D"http://www.w3.org/TR/1999/REC-xml-names-19990114/#dt-prefix"><FON=
T=20
face=3DArial>namespace prefix</FONT></A><FONT face=3DArial>), and to all =
elements=20
with no prefix within the content of that element. If the URI reference =
in a=20
default namespace declaration is empty, then unprefixed elements in the =
scope of=20
the declaration are not considered to be in any namespace. Note that =
default=20
namespaces do not apply directly to attributes. </FONT></P></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&lt;!-- snip --&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>From your original note:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"When I run the NSTest class using the =
Crimson=20
parser, the file gets loaded.<BR><BR>If I use the Xerces parser, I get =
following=20
exception:<BR><BR>org.jdom.JDOMException: Error in building from stream: =
The=20
namespace<BR>xmlns:=3D"http://namespace/ns" could not be added as =
content to=20
"ns1:el1": The<BR>namespace prefix "" collides with an attribute =
namespace on=20
the element "</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>In this case Xerces is right and =
Crimson is=20
wrong.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"If I'm interpreting the XML spec =
correctly, you=20
can start declaring a default namespace (one without prefix) anywhere in =
the XML=20
document. If another one already declared somewhere up the parent tree, =
it will=20
override it."</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>True, but only for that element and any =
child=20
elements.&nbsp;The namespace will no apply&nbsp;to parent =
elements.&nbsp; If you=20
want the root element to belong to the default namespace, it must =
declared at=20
the root element.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Kind regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Eric</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dwcordewiner at hotmail.com =
href=3D"mailto:wcordewiner at hotmail.com">Wouter=20
  Cordewiner</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Deasirois at hotmail.com=20
  href=3D"mailto:easirois at hotmail.com">Eric A. Sirois</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A =
title=3Djdom-interest at jdom.org=20
  href=3D"mailto:jdom-interest at jdom.org">jdom-interest at jdom.org</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, November 28, =
2001 11:54=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] =
JDOM, Xerces=20
  and Crimson with namepsaces</DIV>
  <DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><FONT=20
  face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>with the example you provide below, =
the root=20
  element will belong to the 'ns1' namespace, while in my example the =
root=20
  element belongs to no namespace.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>If I'm interpreting the XML spec =
correctly, you=20
  can start declaring a default namespace (one without prefix) anywhere =
in the=20
  XML document. If another one already declared somewhere up the parent =
tree, it=20
  will override it.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Anyway, my test xml example =
was&nbsp;just&nbsp;to=20
  illustrate that when loading the XML through JDOM using the Xerces =
parser it=20
  fails, while using the Crimson it doesn't.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>In my humble opinion, it seems like =
something is=20
  not consistent.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Wouter Cordewiner</FONT></DIV>
  <BLOCKQUOTE dir=3Dltr=20
  style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
    <DIV=20
    style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
    <A title=3Deasirois at hotmail.com =
href=3D"mailto:easirois at hotmail.com">Eric A.=20
    Sirois</A> </DIV>
    <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dwcordewiner at hotmail.com=20
    href=3D"mailto:wcordewiner at hotmail.com">Wouter Cordewiner</A> </DIV>
    <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A =
title=3Djdom-interest at jdom.org=20
    href=3D"mailto:jdom-interest at jdom.org">jdom-interest at jdom.org</A> =
</DIV>
    <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, November 27, =
2001 11:41=20
    PM</DIV>
    <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [jdom-interest] =
JDOM,=20
    Xerces and Crimson with namepsaces</DIV>
    <DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><FONT=20
    face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><FONT face=3DArial=20
    size=3D2></FONT><BR></DIV>
    <DIV><!--StartFragment --><FONT face=3DArial =
size=3D2>&nbsp;Hello,<BR></FONT><PRE wrap=3D""><FONT face=3DArial =
size=3D2>The example below should work for you.  For element "el1" you =
assigned it the default namespace "<A =
href=3D"http://namespace/ns">http://namespace/ns</A>" but added the =
prefix for the ns1 prefix.  <BR><BR>The error message you&nbsp;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=3D""><FONT face=3DArial size=3D2><BR><BR><BR>&lt;?xml =
version=3D"1.0" encoding=3D"UTF-8" ?&gt;<BR>&lt;ns1:root =
xmlns:ns1=3D"http://namespace/ns1"&gt;<BR>  &lt;el1 =
xmlns=3D"http://namespace/ns" att1=3D"Attribute 1" =
/&gt;<BR>&lt;/ns1:root&gt;</FONT></PRE><FONT=20
    face=3DArial size=3D2>namespace &nbsp;&nbsp;&nbsp;=20
    element<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    =
&nbsp;ns1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;root<BR>&nbsp;&nbsp;&nbsp;=20
    &nbsp;&nbsp;=20
    =
default&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;el1<BR=
><BR>If=20
    &nbsp;you need the &nbsp;XML as-is try<BR></FONT><PRE =
wrap=3D""><FONT face=3DArial size=3D2>&lt;?xml version=3D"1.0" =
encoding=3D"UTF-8" ?&gt;<BR>&lt;root =
xmlns=3D"http://namespace/ns"&gt;<BR>  &lt;ns1:el1 =
xmlns:ns1=3D"http://namespace/ns1" att1=3D"Attribute 1" =
/&gt;<BR>&lt;/root&gt;</FONT></PRE><BR><BR><FONT=20
    face=3DArial size=3D2>HTH,<BR><BR>Eric<BR><BR>Wouter Cordewiner=20
wrote:<BR></FONT>
    <BLOCKQUOTE cite=3Dmid:OE12GvelgED05qr36VV0000deca at hotmail.com =
type=3D"cite"><PRE wrap=3D""><FONT face=3DArial size=3D2>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>&lt;?xml =
version=3D"1.0" encoding=3D"UTF-8" ?&gt;<BR><BR>&lt;root =
xmlns:ns1=3D"http://namespace/ns1"&gt;<BR><BR>  &lt;ns1:el1 =
xmlns=3D"http://namespace/ns" att1=3D"Attribute 1" =
/&gt;<BR><BR>&lt;/root&gt;<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 =3D new =
org.jdom.input.DOMBuilder();<BR>   org.jdom.Document doc =3D 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:=3D"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:=3D"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-interes=
t/youraddr at yourhost.com<BR><BR></FONT></PRE></BLOCKQUOTE><BR></DIV></BLOC=
KQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0046_01C1780F.F8DDE9E0--



More information about the jdom-interest mailing list