[jdom-interest] cannot create xmlns namespace?

Bradley S. Huffman hip at a.cs.okstate.edu
Sun Jul 21 07:45:24 PDT 2002

Phillip Rhodes writes:

> Thanks.  That kind of worked...
> But now I have xmlns declarations on all my child elements.  I know I can 
> add the namespace manually on all my children content, but that would 
> create like <html:head></html:head> instead of <head></head>
> Is there anyway to add a namespace to a element so that doesn't 
> happen?  What I want is this:
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Test</title>
> Here is what is happening now:
> <html xmlns="http://www.w3.org/1999/xhtml">
>     <head xmlns="" xmlns="http://www.w3.org/1999/xhtml">
>        <title xmlns="" xmlns="http://www.w3.org/1999/xhtml">Test</title>
>     </head>

If your using XMLOutputter with newlines set you should get what you

    XMLOutputter output = new XMLOutputter();
    // output.setIndent("    "); // if you also want the output indented

    output(element, System.out);

XMLOuputter keeps track of which namespace declarations have been printed and
doesn't print a declaration for every element.


More information about the jdom-interest mailing list