I am using a Transform
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
A text node without text is not a text node.
If you are trying to control how the XML element is serialized,
and
are equivalent, and it will not matter to an XML processor if either was used. Both are declaring a TYPE element without any text()
. Most processors will serialize an empty element as a self-closing element.
If you really want to prevent the element from being serialized as self-closing, you could get cute and add a zero-width space as the text node value:
which will look like:
.
It isn't technically an "empty" string, but might achieve what you want, and will not pad with space if the text node is selected and used.