[jdom-interest] Namespaces and XMLOutputter

Knorr, Christian Christian.Knorr at astrium-space.com
Fri Jan 19 03:46:05 PST 2001


Your code worked perfectly with my file, the output was exactly like the
input. But I realized that I used DOMBuilder instead of SAXBuilder and
this reproduces the error. 

Here is my code:

import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

public class TestClass {

  public static void main(String[] args) throws Exception {
    try {
      FileInputStream in = new FileInputStream(args[0]);
      Document d = new DOMBuilder().build(in);
      XMLOutputter outp = new XMLOutputter("", false);
      outp.output(d, System.out);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

And the output:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE
a:messagelist><a:messagelist xml
ns:a="http://www.a.com">
        <b:message1 xmlns:b="http://www.b.com">
                <c:item1 xmlns:c="http://www.c.com" value="500" />
        </b:message1>
</a:messagelist>
C:\usr\ck\prj\vadis\prototype\bin>

Christian Knorr

Jason Hunter wrote:
> 
> I sent in the code I was using, the file I was reading, and the output I
> was seeing.  Did you try my specific code/doc example?  Did it work?
> You didn't send in yours, so I can't reproduce your problem.
> 
> To proceed from here, we need to know if what works for me works for
> you.  If my test fails on your machine, it's a config thing.  If it
> works on your machine, then it's a code thing and I need you to send in
> the same code/doc info I sent in so I can see the failure on my machine.
> 
> -jh-
> 
> Christian Knorr wrote:
> >
> > I experience the same effect as Thomas does. The point is, if I create a
> > new JDOM document with namespace declarations in the root-element it
> > will be written as expected, but if I read this document in again and
> > write it back without any changes, the root-element looses its
> > additional namespace declarations and they appear in each element where
> > they are used.
> >
> > Christian Knorr
> >
> > P.S.: I also downloaded the CVS-version a couple of days ago.
> >
> > Jason Hunter schrieb:
> > >
> > > It works on my machine.  I saved your file to ns.xml, and ran this code
> > > on it:
> > >
> > > import java.util.*;
> > > import org.jdom.*;
> > > import org.jdom.input.*;
> > > import org.jdom.output.*;
> > >
> > > public class Tester2 {
> > >
> > >   public static void main(String[] args) throws Exception {
> > >     Document d = new SAXBuilder().build(args[0]);
> > >     XMLOutputter outp = new XMLOutputter("", false);
> > >     outp.output(d, System.out);
> > >   }
> > > }
> > >
> > > Here's the output:
> > >
> > > % java Tester2 ns.xml
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <a:messagelist xmlns:a="http://www.a.com" xmlns:b="http://www.b.com"
> > > xmlns:c="http://www.c.com">
> > > <b:message1>
> > > <c:item1 value="500" />
> > > </b:message1>
> > > </a:messagelist>C:/tmp/jdom 30 %
> > >
> > > -jh-
> > >
> > > Thomas Riessler wrote:
> > > >
> > > > Hi,
> > > > if I build a JDOM Document object from the following XML source (using SAXBuilder):
> > > >
> > > > <?xml version="1.0" encoding="ISO-8859-1"?>
> > > > <a:messagelist xmlns:a="http://www.a.com" xmlns:b="http://www.b.com" xmlns:c="http://www.c.com">
> > > > <b:message1>
> > > > <c:item1 value="500"/>
> > > > </b:message1>
> > > > </a:messagelist>
> > > >
> > > > and printout this unchanged Document with the output method of XMLOutputter, I do not get the same XML source returned. Instead output() writes the following code:
> > > >
> > > > <?xml version="1.0" encoding="ISO-8859-1"?>
> > > > <a:messagelist xmlns:a="http://www.a.com">
> > > > <b:message1 xmlns:b="http://www.b.com">
> > > > <c:item1 xmlns:c="http://www.c.com" value="500"/>
> > > > </b:message1 xmlns:b="http://www.b.com">
> > > > </a:messagelist xmlns:a="http://www.a.com">
> > > >
> > > > Note that the namespace declarations (including URLs) have moved from the root element to all Elements affected by a namespace prefix.
> > > >
> > > > This occurs with beta 5 and the nightly build I downloaded today.
> > > > This is kind of a suprise to me since this problem (among others) was adressed by Kesav Kumar in his post on "Namespace prefix" (Fri, 13 Oct 2000 15:11:46 -0700 ) and has been reported to be fixed.
> > > >
> > > > This presents a big jdom usability problem to our project (we're currently evaluating it) since our XML docs are large and the namespace declarations would have a huge performance impact.
> > > > Besides that, the target application we want to communicate with, cannot handle these declarations. Whats the current status of the problem?
> > > >
> > > > Thomas Riessler
> > > >
> > > > --
> > > >
> > > > Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
> > > >
> > > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
> > > >
> > > > _______________________________________________
> > > > To control your jdom-interest membership:
> > > > http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> > >
> > > _______________________________________________
> > > To control your jdom-interest membership:
> > > http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
Christian Knorr, Astrium GmbH, Bremen / Germany
email:  christian.knorr at astrium-space.com
phone:  +49 (0)421 / 539 - 5673



More information about the jdom-interest mailing list