Help at DOMOutputter!!(was RE: [jdom-interest] Help at XMLOutputter!!)
Itoh, Kazuhiro
kazuhiro-i at kajima.com
Thu Oct 23 23:45:07 PDT 2003
Thank you for useful information. I should learn more....
By the way, I found a workaround.
To Translate JDOM to W3C-DOM, I used JDOMSource not DOMOutputter
Let me show you this.
<1st case -- duplicate namespace declaration>
DOMOutputter outPutter = new DOMOutputter();
w3ddoc = outPutter.output(jdom);
<2nd case -- unique namespace declaration>
JDOMSource js = new JDOMSource(jdom);
js.setDocument(jdom);
w3cdoc = org.apache.axis.utils.XMLUtils.newDocument(js.getInputSource());
At 2nd case I got a requested outcome.
Thank you.
-----Original Message-----
From: Per Norrman [mailto:pernorrman at telia.com]
Sent: Thursday, October 23, 2003 7:32 PM
To: Itoh, Kazuhiro; jdom-interest at jdom.org
Subject: SV: Help at DOMOutputter!!(was RE: [jdom-interest] Help at XMLOutputter!!)
Hi,
this is tricky. DOMOutputter creates the DOM element
as being in the specified namespace *and* adds a namespace declaration attribute.
Then comes the Axis serializer, which looks at the DOM element, recognises that it belongs to the fooBar namespace and creates a new namespace declaration attribute. It then simply spits out all attributes belonging to the element, of which one is the namespace declaration. This is why you get two namespace
declarations.
Since serialization isn't defined for DOM level 2, this is
a gray area where you cannot really say who's wrong and who's right. Here are two arguments that both parties are in error:
1. DOMOutputter should not declare any namespace attributes
at all. Such attributes are useful only when reading the XML into a DOM document. Leave it to the serializer to fix the declarations.
2. The Axis serializer should check existing attributes before creating the namespace declaration.
For DOM level 3, there is a namespace normalization algorithm defined
here:
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030609/namespaces-algorithms
.html
Your best work-around would be to walk through all attributes in the document and remove all that starts with "xmlns:".
/pmn
> -----Ursprungligt meddelande-----
> Från: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org] För Itoh, Kazuhiro
> Skickat: den 23 oktober 2003 11:01
> Till: jdom-interest at jdom.org
> Ämne: Help at DOMOutputter!!(was RE: [jdom-interest] Help at
> XMLOutputter!!)
>
>
> Dear All
> I made a mistake in subject.
> Not XMLOutputter But DOMOutputter......
> So I re-send....sorry.
>
> ----------------message starts from
> here----------------------- Dear All: I am Kazuhiro from
> Japan. I met strange outcome using DOMOutputter. (JDOM
> version is beta9,
> JDK version is 1.4.1_03, OS Win2k)
>
> Here is the portion of my program.
>
> //Create JDOM using Namespace declaration
> SAXBuilder builder = new SAXBuilder();
> Document jdom = new Document();
> Namespace ns= Namespace.getNamespace("myspace", "fooBar");
> jdom.setRootElement(new Element("return", ns));
> jdom.getRootElement().setText("Foo Bar"); //Write this JDOM
> XMLOutputter xmlOut = new XMLOutputter(" ",true);
> xmlOut.output(jdom, new FileWriter("c:\\temp\\fooBarJDOM.xml"));
>
> Then let me show you the output by above statement.
> <?xml version="1.0" encoding="UTF-8"?>
> <myspace:return xmlns:myspace="fooBar">Foo Bar</myspace:return>
>
> Then I translated jdom to w3c Document like following...
>
> //JDOM->W3C
> DOMOutputter outPutter = new DOMOutputter();
> org.w3c.dom.Document doc = null; doc =
> outPutter.output(jdom); //Write w3c Document using AXIS
> Utility(This fragment from certain Web
> Services)
> org.apache.axis.utils.XMLUtils.DocumentToWriter(doc, new
> FileWriter("c:\\temp\\fooBarDOM.xml"));
>
> The above output is here.
> <?xml version="1.0" encoding="UTF-8"?>
> <myspace:return xmlns:myspace="fooBar"
> xmlns:myspace="fooBar">Foo Bar</myspace:return>
>
> There is duplicate Namespace declaration in the
> root-tag<return>. Is this Bug? or is my way wrong?
>
> Please help me. _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
More information about the jdom-interest
mailing list