title: How to create an XML text node with an empty string value (in Java)
body: <p>I am using a <code>Transform</code> object to save my XML file but it seems to drop empty text nodes.  Is there any way to create (and keep) a text node with an empty string i.e. "".</p>
  
  <p>Here is how I create the node:</p>
  
  <pre><code>Element type = doc.createElement("TYPE");
  
  type.appendChild(doc.createTextNode(value));
  </code></pre>
  
  <p>It is just that sometimes <code>value</code> is an empty string "".  When I look at the XML with a text editor I see</p>
  
  <pre><code>&lt;TYPE /&gt;
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>&lt;TYPE&gt;&lt;/TYPE&gt;
  </code></pre>
  
  <p>After I read this XML file back in and traverse the nodes the &lt;TYPE&gt; element simply doesn't have any children even though I explicitly created one #text node for it!</p>
  
  <p>EDIT - Happy Thanksgiving (for my fellow Canadians)</p>
  
  <p>Important note, I am not working from a known set of tags, rather the program I am working on uses the presence of a text node to assign a <code>JTextField</code> to the GUI.  It is just that sometimes the field is left empty (not null but "").  When I store that field and then read it back the GUI doesn't render the <code>JTextField</code> anymore because there is no text node.  So I am looking at ways to create an XML document that creates a text node even if there is nothing in it.  If that simply can't be done with XML then I will have to use an attribute to mark tags that are editable (somewhat like Andrey Breslav suggested) and so should have a <code>JTextField</code> assigned.</p>
  
  <p>I will try Mads Hansen's suggestion of a non-breaking space.</p>