Help at DOMOutputter!!(was RE: [jdom-interest] Help at XMLOutputter!!)

Bradley S. Huffman hip at cs.okstate.edu
Fri Oct 24 08:57:30 PDT 2003


I'd report your initial results to the AXIS group anyway.  A quick look at
AXIS cvs tree showed that XMLUtils is really using DOM2Writer to do the
serialization. And the javadoc for DOM2Writer say

    This class is a utility to serialize a DOM node as XML.

If it's putting duplicate attributes on a element, that ain't XML and that's
either a bug or their javadocs are wrong.  Looking at the code I couldn't
see anything obvious so they might have already fixed it.

Brad

"Itoh, Kazuhiro" writes:

> 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 =3D new DOMOutputter();
> w3ddoc =3D outPutter.output(jdom);
> 
> <2nd case -- unique namespace declaration>
> JDOMSource js =3D new JDOMSource(jdom);
> js.setDocument(jdom);
> w3cdoc =3D =
> 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]=20
> 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=20
> 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-algorit=
> hms
> .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=E5n: jdom-interest-admin at jdom.org
> > [mailto:jdom-interest-admin at jdom.org] F=F6r Itoh, Kazuhiro
> > Skickat: den 23 oktober 2003 11:01
> > Till: jdom-interest at jdom.org
> > =C4mne: Help at DOMOutputter!!(was RE: [jdom-interest] Help at=20
> > XMLOutputter!!)
> >=20
> >=20
> > Dear All
> > I made a mistake in subject.
> > Not XMLOutputter But DOMOutputter......
> > So I re-send....sorry.
> > =20
> > ----------------message starts from
> > here----------------------- Dear All: I am Kazuhiro from=20
> > Japan. I met strange outcome using DOMOutputter. (JDOM=20
> > version is beta9,=20
> > JDK version is 1.4.1_03, OS Win2k)
> >=20
> > Here is the portion of my program.
> >=20
> > //Create JDOM using Namespace declaration
> > SAXBuilder builder =3D new SAXBuilder();
> > Document jdom =3D new Document();
> > Namespace ns=3D Namespace.getNamespace("myspace", "fooBar");
> > jdom.setRootElement(new Element("return", ns));=20
> > jdom.getRootElement().setText("Foo Bar"); //Write this JDOM=20
> > XMLOutputter xmlOut =3D new XMLOutputter(" ",true);=20
> > xmlOut.output(jdom, new FileWriter("c:\\temp\\fooBarJDOM.xml"));
> >=20
> > Then let me show you the output by above statement.
> > <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> > <myspace:return xmlns:myspace=3D"fooBar">Foo Bar</myspace:return>
> >=20
> > Then I translated jdom to w3c Document like following...
> >=20
> > //JDOM->W3C
> > DOMOutputter outPutter =3D new DOMOutputter();
> > org.w3c.dom.Document doc =3D null; doc =3D=20
> > outPutter.output(jdom); //Write w3c Document using AXIS=20
> > Utility(This fragment from certain Web
> > Services)
> > org.apache.axis.utils.XMLUtils.DocumentToWriter(doc, new=20
> > FileWriter("c:\\temp\\fooBarDOM.xml"));
> >=20
> > The above output is here.
> > <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> > <myspace:return xmlns:myspace=3D"fooBar"
> > xmlns:myspace=3D"fooBar">Foo Bar</myspace:return>
> >=20
> > There is duplicate Namespace declaration in the
> > root-tag<return>. Is this Bug? or is my way  wrong?
> >=20
> > Please help me. _______________________________________________
> > To control your jdom-interest membership:=20
> > http://lists.denveronline.net/mailman/options/jdom-interest/yo
> uraddr at yourhost.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost
> .com



More information about the jdom-interest mailing list