[jdom-interest] cannot create xmlns namespace?

Bradley S. Huffman hip at a.cs.okstate.edu
Sun Jul 21 19:57:05 PDT 2002


This will do it.

      // Map default namespace to "http://www.w3.org/1999/xhtml"
      Namespace ns2 = Namespace.getNamespace("http://www.w3.org/1999/xhtml");

      // Create elements in the "http://www.w3.org/1999/xhtml" namespace
      Element html = new Element("html",ns2);
      Element head = new Element("head",ns2);
      Element title= new Element("title",ns2);

      html.addContent(head);
      title.addContent("test");
      head.addContent(title);

      // Output with each element on a new line
      XMLOutputter output = new XMLOutputter();
      output.setNewlines(true);
      output.output(html, System.out);

Brad
 
Phillip Rhodes writes:

> Here is the code that will generate the invalid jdom document.  I know I 
> probably did something bone-headed...
> 
>          Element html = new Element("html");
>          Namespace ns2 = 
> Namespace.getNamespace("http://www.w3.org/1999/xhtml");
>          html.addNamespaceDeclaration(ns2);
>          Element head = new Element("head");
>          head.addNamespaceDeclaration(ns2);
>          html.addContent(head);
>          Element title= new Element("title");
>          title.addContent("test");
>          title.addNamespaceDeclaration(ns2);
>          head.addContent(title);
> 
> All I want is this:
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Test</title>
> </head>
> </title>
> 
> Thanks!
> 
> 
> 
> At 05:00 PM 7/21/2002 -0700, Jason Hunter wrote:
> > > 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>
> >
> >That's not valid XML, and I'm surprised XMLOutputter would emit that.
> >Could you send some sample code (as simple as possible) that generates
> >that document?
> >
> >-jh-
> >_______________________________________________
> >To control your jdom-interest membership:
> >http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
> 



More information about the jdom-interest mailing list