[jdom-interest] Namespaces and XMLOutputter

Jason Hunter jhunter at collab.net
Thu Jan 25 08:41:13 PST 2001


I see the same error (thanks for including a short reproducible
example).  Seems DOMBuilder needs add'l logic to understand attribute
namespace prefixes.  SAXBuilder works just fine.

-jh-

"Knorr, Christian" wrote:
> 
> Well, it was not beta5 but the cvs build from December, 13. But you are
> right, DOMBuilder makes absolutely no sense so I switched my project to
> SAXBuilder now.
> However, I downloaded the lates daily snapshot from tonight and ran into
> another problem regarding DOMBuilder. This former testfile works fine
> with DOMBuilder but I used another one that fails:
> 
> The original file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE Test>
> <Test xmlns:xlink="http://www.w3.org/1999/xlink">
>   <Link ID="1" xlink:type="extended">
>     <Source xlink:href="2" xlink:type="locator" />
>     <Target xlink:href="3" xlink:type="locator" />
>   </Link>
> </Test>
> 
> Still the old 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 here the output:
> 
> org.jdom.JDOMException: Error in building from stream: The name
> "xlink:type" is
> not legal for JDOM/XML attributes: Attribute names cannot contain
> colons.
>         at org.jdom.input.DOMBuilder.build(DOMBuilder.java:172)
>         at
> com.astrium.vadis.testClasses.TestClass.main(TestClass.java:12)
> Root cause: org.jdom.IllegalNameException: The name "xlink:type" is not
> legal fo
> r JDOM/XML attributes: Attribute names cannot contain colons.
>         at org.jdom.Attribute.<init>(Attribute.java:110)
>         at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:324)
>         at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:340)
>         at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:272)
>         at org.jdom.input.DOMBuilder.build(DOMBuilder.java:169)
>         at
> com.astrium.vadis.testClasses.TestClass.main(TestClass.java:12)
> 
> I had this error long time ago and it seemed to be fixed since then...
> 
> Christian Knorr
> 
> Jason Hunter wrote:
> >
> > Thanks for sending in the code for me to try.  I think you're still
> > running against beta5 somehow.  I fixed this exact xmlns placement bug
> > in DOMBuilder about 2-3 weeks ago and daily snapshot I have behaves
> > correctly:
> >
> > C:/tmp/jdom 64 % java TestClass ns.xml
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE a:messagelist><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>
> >
> > I see also you don't have the recent XMLOutputter fix to move the
> > <!DOCTYPE> after the decl line.  Pretty clear your output was generated
> > by beta5 code.
> >
> > -jh-
> >
> > P.S.  Anyone out there using DOMBuilder should switch to SAXBuilder
> > where possible.  It's far faster, as the DOMBuilder docs warn.
> >
> --
> 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