How to create an XML text node with an empty string value (in Java) -
i using transform
object save xml file seems drop empty text nodes. there way create (and keep) text node empty string i.e. "".
here how create node:
element type = doc.createelement("type"); type.appendchild(doc.createtextnode(value));
it value
empty string "". when @ xml text editor see
<type />
instead of
<type></type>
after read xml file in , traverse nodes <type> element doesn't have children though explicitly created 1 #text node it!
edit - happy thanksgiving (for fellow canadians)
important note, not working known set of tags, rather program working on uses presence of text node assign jtextfield
gui. field left empty (not null ""). when store field , read gui doesn't render jtextfield
anymore because there no text node. looking @ ways create xml document creates text node if there nothing in it. if can't done xml have use attribute mark tags editable (somewhat andrey breslav suggested) , should have jtextfield
assigned.
i try mads hansen's suggestion of non-breaking space.
a text node without text is not text node.
if trying control how xml element serialized, <type/>
, <type></type>
equivalent, , not matter xml processor if either used. both declaring type element without text()
. processors serialize empty element self-closing element.
if want prevent element being serialized self-closing, cute , add zero-width space text node value: <type>​</type>
like: <type></type>
.
it isn't technically "empty" string, might achieve want, , not pad space if text node selected , used.
Comments
Post a Comment