<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<html>
<head>
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>RE: [jdom-interest] The default namespace behaviour </title>
<style>
<!--
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
p
        {margin-right:0in;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.emailstyle18
        {font-family:Arial;
        color:navy;}
span.EmailStyle20
        {font-family:Arial;
        color:navy;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<DIV id=idOWAReplyText90632 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Michael and Paul are spot on
- you're conflating the XML file ("lexical XML") with the XML document (the
document object model [note the lower case]).</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>This may sound odd, but if you really want
to do the transformation you describe below, why deal with JDOM at all? Instead
do:</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>// read the file into String object
docAsString</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>docAsString =
docAsString.replaceAll("xmlns=\"one\"", "xmlns=\"two\");</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>If you wanted, you could then parse this
String using StringReader:</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>Document doc = saxBuilder.build(new
StringReader(docAsString));</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>> <SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">This doesn’t fit the
XML idea that, if you change the parent’s namespace, un-prefixed children will
implicitly</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">> change their
namespace.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Can you provide a
reference for where this "XML idea" is documented? DOM doesn't provide mutators
for namespace, so this isn't remotely possible in the DOM world and I don't
think there are many other XML specs that address changing
documents.</SPAN></FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org on behalf
of Colin LeMahieu<BR><B>Sent:</B> Wed 6/7/2006 1:37 AM<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> RE: [jdom-interest] The default
namespace behaviour <BR></FONT><BR></DIV>
<DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">I was hoping to mimic
the behavior that XML files have. When using the default namespace, all
un-prefixed sub elements are within that namespace.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><a
xmlns=”one”></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">
<b/></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">
<c/></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></a></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">The b and c tags are in
the “one” namespace.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">If I changed this
to:</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><a
xmlns=”two”></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">
<b/></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">
<c/></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></a></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">The b and c tags are in
the “two” namespace. I made one small change to a and got a side-effect of
changing b and c; this is how it works with written XML
documents.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">If I parsed the first
example and generated a JDOM model and called
a.setNamespace(Namespace.getNamespace(“two”)) and then spit the file out, what I
would have, essentially, is:</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><a
xmlns=”two”></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> <b
xmlns=”one”/></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> <c
xmlns=”one”/></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></a></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">This doesn’t fit the
XML idea that, if you change the parent’s namespace, un-prefixed children will
implicitly change their namespace.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<DIV>
<P class=MsoAutoSig><FONT face="Times New Roman" color=navy size=3><SPAN
style="FONT-SIZE: 12pt; COLOR: navy">----------------</SPAN></FONT></P>
<P class=MsoAutoSig><FONT face="Times New Roman" color=navy size=3><SPAN
style="FONT-SIZE: 12pt; COLOR: navy">Colin LeMahieu</SPAN></FONT></P>
<P class=MsoAutoSig><FONT face="Times New Roman" color=navy size=3><SPAN
style="FONT-SIZE: 12pt; COLOR: navy">Phone: 408-499-5269</SPAN></FONT></P>
<P class=MsoAutoSig><FONT face="Times New Roman" color=navy size=3><SPAN
style="FONT-SIZE: 12pt; COLOR: navy">Fax: </SPAN></FONT><FONT color=black><SPAN
style="COLOR: black">267-989-4575</SPAN></FONT></P>
<P class=MsoAutoSig><FONT face="Times New Roman" color=black size=3><SPAN
style="FONT-SIZE: 12pt; COLOR: black">Email:
clemahieu@gmail.com</SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Times New Roman" size=2><SPAN
style="FONT-SIZE: 10pt">I strongly disagree with your sense
that:</SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=2><SPAN
style="FONT-SIZE: 10pt">a.setNamespace(namespace.getNamespace("ReallyLongNamespace"));</SPAN></FONT></P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
style="FONT-SIZE: 12pt"></SPAN></FONT> </P></DIV>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" size=2><SPAN
style="FONT-SIZE: 10pt">should set the namespace for all child elements that use
the same default namespace as a. This would be a big leap for JDOM to make.
Since it's entirely legitimate to have different default namespaces at different
levels, having JDOM guess which ones you wanted to change would invariably be
incorrect (in other words, what if I really wanted setNamespace() to just set
that element's namespace). Writing the getDescendents()-using code above or even
better, as Mr. Huffman suggested, a custom JDOMFactory would be the best way to
go about explictingly specifying what transformation you wanted to do.
</SPAN></FONT></P>
<DIV>
<P class=MsoNormal><FONT face="Times New Roman" color=navy size=2><SPAN
style="FONT-SIZE: 10pt; COLOR: navy"></SPAN></FONT> </P></DIV></DIV></DIV></DIV>
</body>
</html>