Element containing only empty text serialized as element with whitespace when
using DOM3 LS format-pretty-print
---------------------------------------------------------------------------------------------------------------
Key: XALANJ-2523
URL: https://issues.apache.org/jira/browse/XALANJ-2523
Project: XalanJ2
Issue Type: Bug
Security Level: No security risk; visible to anyone (Ordinary problems in
Xalan projects. Anybody can view the issue.)
Components: Serialization
Affects Versions: 2.7.1
Environment: Serializing through DOM 3 LS API from included Xerces-J
(2.9.0).
Reporter: Kahmyong Moon
Priority: Minor
I'm using DOM 3 LS to serialize a Document to an OutputStream with the
format-pretty-print option. When I try to serialize an element containing only
an empty text node, it serializes like this:
<Element>
</Element>
When I load the XML later, the element content ends up "\n ", instead of "".
I'm expecting the element to serialize like this:
<Element />
Or at least like this:
<Element></Element>
Text nodes containing only whitespace and containing non-whitespace do
serialize as expected:
<Element> </Element>
<Element>text</Element>
I created the element like this:
Document document;
Element element;
String text = "";
Text textNode = document.createTextNode(text);
element.appendChild(textNode);
As a workaround, if I check in my own code that the text is empty, and don't
add a text node to the element, it serializes as expected:
<Element />
It also works correctly if I normalize the document/element first (which
removes the extraneous text node).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]