[jdom-interest] Bug and query
Bradley S. Huffman
hip at csa.cs.okstate.edu
Tue Jun 24 20:01:46 PDT 2003
Eric VERGNAUD writes:
> Hi,
>
> I'm new to this list, so first I would like to congratulate and thanks the
> people involved in the creation of jdom, which is exactly what I've been
> waiting for to start working with xml.
>
> Haviong said that, I have 2 questions:
>
> - is this the place to file a bug ? If so, here is one:
> in XmlOutputter.java, there is come inconsistency in the way
> printElement, printElementNamespace, and printNamespace work together.
> This sometimes leads to the following production:
>
> <tag xmlns:'mynamesapce'>
> <childtag xmlns:>
> some data
> </childtag>
> </tag>
>
> This happens when you set the namespace for an element, but not for one
> of its child element.
> This can be fixed by changing the code for printElementNamespace by the
> following:
> Namespace ns = element.getNamespace();
> if (ns != Namespace.XML_NAMESPACE && ns != Namespace.NO_NAMESPACE)
> {
> printNamespace(ns, out, namespaces);
> }
Which version of JDOM are you using? In beta 9 and the current cvs, ns should
should never be equal to XML_NAMESPACE (which is prefix "xml"). Using the
prefix "xml" or one that starts with "xml" will throw a exception in
Namespace.getNamespace. Second "xmlns" is only printed in printNamespace()
and it always prints a "=" and surrounds the URI with double quotes, so I
don't see how your example output could happen.
> - is this the place to discuss some implementation choices ? If so, I am
> not convinced by the following:
>
> in XmlOutputter.java, the 'output' method ends by the following code:
>
> // Output final line separator
> // We output this no matter what the newline flags say
> out.write(currentFormat.lineSeparator);
>
> out.flush();
>
> Is writing a line separator at the end of the Xml stream mandatory ? I don't
> know the answer, but I guess it's no, so I think it should be caller's
> responsability to add this newline, because while this newline maybe fine in
> a xml file, it may not be fine at all in a wireless xml stream, when the
> other end is expecting a perfectly-formed (not just well-formed) document.
> In fact I've met the situation where this newline would cause the other end
> parser to fail at some point, and got stuck because I do not have access to
> that parser which resides compiled on a mobile device.
No it's not mandatory, but it should not matter. If it does, then that
application or the parser it uses it broken.
> So I would very much prefer:
>
> // Output final line separator
> // We output this no matter what the newline flags say
> newline(out);
>
> out.flush();
>
> What do you think ?
Have to look, but not printing it when in "raw" mode and printing it
when in "pretty-printing" mode seems harmless and reasonable.
Brad
More information about the jdom-interest
mailing list