[jdom-interest] XMLOutputter considers spaces content as empty when XMLOutputter( " ", true) Constructor is used.

Vinayrani Gurram Vinayrani.Gurram at Metaserver.com
Tue Sep 17 12:39:58 PDT 2002


Hi,
 
JDom beta version 8 seems to have an issue where it ignores the element
content that has only space(s) and writes it as an empty element.
 
The problem arises only when XMLOutputter(" ", true) constructor is used.
 
The following is a sample code: 
 
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
 
import java.io.FileWriter;
import java.io.IOException;
 

public class JdomTest
{
   public JdomTest()
   {
      Element root = new Element("Root");
      root.addContent(new Element("child1").addContent("CCCC"));
      root.addContent(new Element("child2").addContent("DDDD"));
      root.addContent(new Element("child3").addContent(" "));
 
      Document doc = new Document(root);
      try
      {
         FileWriter writer = new
FileWriter("e:\\temp\\jdom\\jdom8\\java\\JdomText.xml");
         XMLOutputter outputter = new XMLOutputter(" ", true);
         outputter.output(doc, writer);
 
      }catch(IOException ioe)
      {
         System.out.println(ioe.getMessage());
      }
   }
 
   public static void main(String args[])
   {
 
      JdomTest testing = new JdomTest();
      System.exit(0);
 
   }
}
 
The output is 
<?xml version="1.0" encoding="UTF-8"?>
<Root>
 <child1>CCCC</child1>
 <child2>DDDD</child2>
 <child3 />
</Root>
 
 
instead of
<?xml version="1.0" encoding="UTF-8"?>
<Root>
 <child1>CCCC</child1>
 <child2>DDDD</child2>
 <child3> </child3>
</Root>
 
Thanks 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020917/530d69d0/attachment.htm


More information about the jdom-interest mailing list