[jdom-interest] Small but irritating problem

Per Norrman per.norrman at austers.se
Mon Oct 25 14:50:32 PDT 2004


Hi,

exactly this behaviour was noted two days ago here:
    http://jdom.org/pipermail/jdom-interest/2004-October/014283.html

As I said in reply, I'm not sure why this happens. Xalan and saxon
gives different results. Maybe its due to SAXOutputter
firing a startPrefixMapping even if the first namespace is the
empty unprefixed namespace--at least I think it does that looking
at the code. The behaviour changed for you, maybe it's due a newer
xalan release?

Wait, wasn't there a dicussion of this some half a year ago ......

(intermission)

Yes there was. The code is changed in SAXOutputter. In b9 and before it never
reported mappings for the empty namespace.

/pmn


Jan-Olof Hendig wrote:
> Hello folks,
>  
> Just to get it over with, I'm an XML newbie so keep the flame throwers 
> away for a while please.
>  
> Today I upgraded from JDOM beta 9 to the current release. As they say, 
> better late than never :) My code needed very few changes in order to 
> compile, the constructor for XMLOutputter had changed but that was easy 
> to fix. However when running the code, see below, a small 
> incompatibility surfaced.
>  
> with beta 9 the code below produced the following
>  
> <?xml version="1.0" encoding="UTF-8"?>
> <message>
>    <request>
>       <onlyreturnoutdata>0</onlyreturnoutdata>
>    </request>
> </message>
>  
> however with the current release I got
>  
> <?xml version="1.0" encoding="UTF-8"?>
> <message xmlns:="">
>    <request>
>       <onlyreturnoutdata>0</onlyreturnoutdata>
>    </request>
> </message>
>  
> as you can see the line containing the <message> tag suddenly includes 
> the attribute 'xmlns:=""'
>  
> My question is this, how do I get rid of this xmlns attribute so that 
> the message looks exactly like it did in beta 9?
>  
> Regards
>  
> Jan-Olof Hendig
>  
> /* --------------------- */
>  
>  
> public class TestCase {
>  
>  protected static Document document;
>  protected static Element rootElement;
>  
>  public static void main(String[] args) {
>   rootElement = new Element("message");
>   Element requestElement = new Element("request");
>   Element onlyReturnOutDataElement = new Element("onlyreturnoutdata");
>   onlyReturnOutDataElement.addContent("0");
>   
>   requestElement.addContent(onlyReturnOutDataElement);
>   rootElement.addContent(requestElement);
>   document = new Document(rootElement);
>  
>   System.out.println(documentToString(document, true));
>  }
>  
>  
>  public static String documentToString(Document doc, boolean fIndent) {
>   JDOMSource domSource = new JDOMSource(doc);
>   StringWriter stringWriter = new StringWriter();
>   StreamResult result = new StreamResult(stringWriter);
>        
>   TransformerFactory tFactory = TransformerFactory.newInstance();
>   try {
>    Transformer transformer = tFactory.newTransformer();
>    if (fIndent) {
>        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
>     transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", 
> "3");
>    }
>    else
>        transformer.setOutputProperty(OutputKeys.INDENT, "no");
>    transformer.transform(domSource, result);          
>   }
>   catch (Exception e) {
>    System.out.println(e);  
>   }
>   return stringWriter.toString();
>  }
> }
>  
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list