[jdom-interest] XMLOutputter.output() and xml:lang attribute results in lang output

Alex Rosen arosen at novell.com
Mon Dec 9 12:07:02 PST 2002


I would think that your code should work. A couple of suggestions:

- Maybe DOMBuilder is not doing the right thing. If you parse the JDOM document directly from a file, does it work? If you use DOMBuilder, and you loop over the element's attributes, do you see the xml:lang attribute?

- Any reason you're outputting the root element, instead of the document? I guess it's possible that that's causing the problem. Also, if your document has any comments or PIs before or after the root element, they'll get lost with your code.

Alex

>>> "Butt, Vaughn A." <vaughn.butt at nz.unisys.com> 12/08/02 11:45PM >>>
I am trying to get an org.jdom.Element as a string by using
org.jdom.XMLoutput(Element element,Writer writer) where the writer is a
StringWriter.

My problem is that the source elements with an attribute xml:lang="en-US" in
it are being streamed to my StringWriter as an element with plain
lang="en-US".

I checked the FAQ (http://jdom.org/docs/faq.html) and found that "The
xml:lang and xml:space attributes are special cases that are allowed..." but
it does not say how JDOM deals with them.

I want to the "xml:" included in my output.

Can I do this (eg by set some attribute on XMLOutputter)?

If I can how is it done?

If I can't then please let me know.

TIA (hopefully)
Vaughn Butt
Software Developer


PS. Here is the (rather ugly and slightly incomplete) code that I want to be
able to get this output from.

public class Migration {
    public static void main(String[] args) {
        org.w3c.dom.Document domDocument = methodThatReturnsADOMDocument();

        org.jdom.Document doc = new DOMBuilder().build(domDocument);

        System.out.println(element2String(doc.getRootElement());
    }

    private static String element2String(Element element) {
        String retVal = null;
        XMLOutputter outputter = new XMLOutputter("    ",true);
        try {
            StringWriter sw = new StringWriter();
            outputter.output(element,sw);
            retVal = sw.toString();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return retVal;
    }
}

_______________________________________________
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