[jdom-interest] Small but irritating problem

Jan-Olof Hendig jan-olof.hendig at bredband.net
Thu Oct 28 10:37:35 PDT 2004


Thank you both Bradley and Jason for your replies. I'll try Bradley's patch, 
hopefully it will solve my problem.

Best regards,

Jan-Olof

----- Original Message ----- 
From: "Bradley S. Huffman" <hip at cs.okstate.edu>
To: "Jan-Olof Hendig" <jan-olof.hendig at bredband.net>
Cc: <    >
Sent: Tuesday, October 26, 2004 7:03 PM
Subject: Re: [jdom-interest] Small but irritating problem


> "Jan-Olof Hendig" writes:
>
>> Thank you for your reply (and to the others that replied as well),
>>
>> I tried your workaround, putting it as the first line in documentToString
>> method, i.e.
>>
>>  public static String documentToString(Document doc, boolean fIndent) {
>> 
>> doc.getRootElement().removeNamespaceDeclaration(Namespace.NO_NAMESPACE);
>>     JDOMSource domSource = new JDOMSource(doc);
>>     StringWriter stringWriter = new StringWriter();
>>
>> This does not work for me, the 'xmlns' is still there. Perhaps I've
>> misunderstood how to apply this workaround. Should I place the line
>> somewhere else?
>
> Yes, that workaround won't work since the problem is in SAXOutputter and
> not your document.  First there is a serious problem in addNsAttribute
> which is causing a well-formness error, xmlns:="" is not well-formed.
>
> Second is SAXOutputter is always reporting the default namespace, which 
> may or
> may not be a problem.
>
> Below is a patch to correct the well-formness error. The second problem is
> going to take a little more exploration.
>
> Brad
>
> *** SAXOutputter.java Mon Oct 25 21:59:16 2004
> --- SAXOutputter.new Mon Oct 25 22:00:38 2004
> ***************
> *** 1215,1225 ****
>              if (atts == null) {
>                  atts = new AttributesImpl();
>              }
> !             atts.addAttribute("",                          // namespace
> !                               "",                          // local name
> !                               "xmlns:" + ns.getPrefix(),   // qualified 
> name
> !                               "CDATA",                     // type
> !                               ns.getURI());                // value
>          }
>          return atts;
>      }
> --- 1215,1236 ----
>              if (atts == null) {
>                  atts = new AttributesImpl();
>              }
> !
> !             String prefix = ns.getPrefix();
> !             if (prefix.equals("")) {
> !                 atts.addAttribute("",                        // 
> namespace
> !                                   "",                        // local 
> name
> !                                   "xmlns",                   // 
> qualified name
> !                                   "CDATA",                   // type
> !                                   ns.getURI());              // value
> !             }
> !             else {
> !                 atts.addAttribute("",                        // 
> namespace
> !                                   "",                        // local 
> name
> !                                   "xmlns:" + ns.getPrefix(), // 
> qualified name
> !                                   "CDATA",                   // type
> !                                   ns.getURI());              // value
> !             }
>          }
>          return atts;
>      } 



More information about the jdom-interest mailing list