<!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> 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 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></BODY></HTML>