<!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.2479.6" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><!--StartFragment --><FONT face=Arial size=2>&nbsp;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 "http://namespace/ns" 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=""><FONT face=Arial size=2><BR><BR><BR>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<BR>&lt;ns1:root xmlns:ns1="http://namespace/ns1"&gt;<BR>  &lt;el1 xmlns="http://namespace/ns" att1="Attribute 1" /&gt;<BR>&lt;/ns1:root&gt;</FONT></PRE><FONT 
face=Arial size=2>namespace &nbsp;&nbsp;&nbsp; 
element<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;ns1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root<BR>&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp; 
default&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;el1<BR><BR>If 
&nbsp;you need the &nbsp;XML as-is try<BR></FONT><PRE wrap=""><FONT face=Arial size=2>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<BR>&lt;root xmlns="http://namespace/ns"&gt;<BR>  &lt;ns1:el1 xmlns:ns1="http://namespace/ns1" att1="Attribute 1" /&gt;<BR>&lt;/root&gt;</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>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<BR><BR>&lt;root xmlns:ns1="http://namespace/ns1"&gt;<BR><BR>  &lt;ns1:el1 xmlns="http://namespace/ns" att1="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 = 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></BODY></HTML>