<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2655.35">
<TITLE>RE: [jdom-interest] Bug and query </TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hate to be the one again ... ;-)</FONT>
</P>
<P><FONT SIZE=2>No, it's not useless. Elements with the same tagname in different namespaces are very different Elements.</FONT>
</P>
<P><FONT SIZE=2>Your example:</FONT>
</P>
<P><FONT SIZE=2> <tag xmlns="mynamespace"></FONT>
<BR><FONT SIZE=2> <childtag xmlns=""></FONT>
<BR><FONT SIZE=2> some data</FONT>
<BR><FONT SIZE=2> </childtag></FONT>
<BR><FONT SIZE=2> </tag></FONT>
</P>
<P><FONT SIZE=2>The root element in your example is in the Namespace "mynamespace"</FONT>
</P>
<P><FONT SIZE=2>The childElement is in the namespace "".</FONT>
</P>
<P><FONT SIZE=2>These are very different namespaces!</FONT>
</P>
<P><FONT SIZE=2>Embellising the example to:</FONT>
</P>
<P><FONT SIZE=2> <tag xmlns="mynamespace"></FONT>
<BR><FONT SIZE=2> <childtag xmlns=""></FONT>
<BR><FONT SIZE=2> some data</FONT>
<BR><FONT SIZE=2> </childtag></FONT>
<BR><FONT SIZE=2> <childtag></FONT>
<BR><FONT SIZE=2> some data</FONT>
<BR><FONT SIZE=2> </childtag></FONT>
<BR><FONT SIZE=2> </tag></FONT>
</P>
<P><FONT SIZE=2>The second childtag is in the "mynamespace" Namespace, and the first is in the "" (or NO_NAMESPACE) namespace.</FONT>
</P>
<P><FONT SIZE=2>NO_NAMESPACE is a very useful construct that indicates that an element has NO NAMESPACE (surprise surprise), and NOT having a namespace is just as important as HAVING a namespace. If you want your elements to have a namespace, then you MUST tell JDOM what namespace to give it.</FONT></P>
<P><FONT SIZE=2>The following code creates a JDom document that represents the embellished example.</FONT>
</P>
<P><FONT SIZE=2>Namespace myns = Namespace.getNamespace("mynamespace");</FONT>
<BR><FONT SIZE=2>// Create the root element that looks like <tag xmlns="mynamespace"></FONT>
<BR><FONT SIZE=2>Element tag = new Element("tag", myns);</FONT>
<BR><FONT SIZE=2>//****** Create an element with NO NAMESPACE *********</FONT>
<BR><FONT SIZE=2>//**** in our example it will look like <childtag xmlns=""></FONT>
<BR><FONT SIZE=2>Element firstchild = new Element ("childtag");</FONT>
<BR><FONT SIZE=2>firstchild.addContent("some data");</FONT>
<BR><FONT SIZE=2>//****** Create an element with the SAME Namspace as the root... *********</FONT>
<BR><FONT SIZE=2>//**** in our example it will look like <childtag> because once we tag.addContent(secondchild)</FONT>
<BR><FONT SIZE=2>// then <childtag xmlns="mynamspace"> is redundant and we only need to have <childtag></FONT>
<BR><FONT SIZE=2>Element secondchild = new Element ("childtag", myns);</FONT>
<BR><FONT SIZE=2>secondchild.addContent("some data");</FONT>
<BR><FONT SIZE=2>tag.addContent(firstchild);</FONT>
<BR><FONT SIZE=2>tag.addContent(secondchild);</FONT>
</P>
<P><FONT SIZE=2>Have a look through, and figure out where your confusion is. Although in XML it feels like a Namespace is "inherited", when you create an Element in JDom, you have to tell JDom what Namespace it is in.</FONT></P>
<P><FONT SIZE=2>The Parser you are using is not an XML compliant parser. Use one that is.</FONT>
</P>
<P><FONT SIZE=2>Before using namespaces in a document, learn how they work, and how they are specified in JDom.</FONT>
</P>
<P><FONT SIZE=2>Changing the way JDom currently does Namespaces would not be adding a Feature, but breaking it.</FONT>
</P>
<P><FONT SIZE=2>Rolf</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Eric VERGNAUD [<A HREF="mailto:eric.vergnaud@wanadoo.fr">mailto:eric.vergnaud@wanadoo.fr</A>]</FONT>
<BR><FONT SIZE=2>Sent: Wednesday, June 25, 2003 8:27 AM</FONT>
<BR><FONT SIZE=2>To: 'jdom-interest@jdom.org'</FONT>
<BR><FONT SIZE=2>Subject: Re: [jdom-interest] Bug and query </FONT>
</P>
<BR>
<P><FONT SIZE=2>le 25/06/03 13:01, Rolf Lear à rlear@algorithmics.com a écrit :</FONT>
</P>
<P><FONT SIZE=2>> Hate to be the one to inform you, but JDom is correct, and the produced code</FONT>
<BR><FONT SIZE=2>> XML exactly represents the XML you asked JDom to create.</FONT>
</P>
<P><FONT SIZE=2>I'm glad to be informed, I'm not a member of the "I'm the one who's right"</FONT>
<BR><FONT SIZE=2>congregation, to which many programmers seem to belong.</FONT>
</P>
<P><FONT SIZE=2>> Creating an Element without a Namespace argument with "new Element</FONT>
<BR><FONT SIZE=2>> (tagname)" is exactly equivalent to creating an element as "new Element</FONT>
<BR><FONT SIZE=2>> (tagname, Namespace.NO_NAMESPACE)". If you want to put an element into a</FONT>
<BR><FONT SIZE=2>> namespace, you have to tell JDom what namespace to use.</FONT>
</P>
<P><FONT SIZE=2>Yes this was fine.</FONT>
</P>
<P><FONT SIZE=2>> Further, xmlns="" is perfectly valid, and a parser which does not parse it</FONT>
<BR><FONT SIZE=2>> is not XML Compliant.</FONT>
</P>
<P><FONT SIZE=2>BUT it's useless (isn't it ?). So let's call this a feature request rather</FONT>
<BR><FONT SIZE=2>than a bug, even though it ends up with a bug in my situation because the</FONT>
<BR><FONT SIZE=2>client parser (a very specialized one, and apparently a pretty bogus one)</FONT>
<BR><FONT SIZE=2>does not seem to support empty namespaces.</FONT>
</P>
<P><FONT SIZE=2>> Have a look at <A HREF="http://www.w3.org/TR/REC-xml-names/#defaulting" TARGET="_blank">http://www.w3.org/TR/REC-xml-names/#defaulting</A> and scan down to</FONT>
<BR><FONT SIZE=2>> where it says "The default namespace can be set to the empty string. This has</FONT>
<BR><FONT SIZE=2>> the same effect, within the scope of the declaration, of there being no</FONT>
<BR><FONT SIZE=2>> default namespace."</FONT>
</P>
<P><FONT SIZE=2>Thanks very much for this useful link.</FONT>
</P>
<P><FONT SIZE=2>Eric</FONT>
</P>
<P><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>To control your jdom-interest membership:</FONT>
<BR><FONT SIZE=2><A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com" TARGET="_blank">http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</A></FONT>
</P>
</BODY>
</HTML>