Reputation: 141
I have a requirement according to which i need to send some trailing whitespaces(tabs) in the end of xml tag like below:-
<ImportFile Name="32201">Type Action </ImportFile>
I am using xmlbeans to set the value in tags:-
ImportFile importFile = importOption.addNewImportFile();
importFile.setName("Id");
importFile.setStringValue(value);
But by using above all trailing whitespaces get deleted and result in following structure:-
<ImportFile Name="32201">Type Action</ImportFile>
P.S. I am not using pretty print XMLoption
Upvotes: 1
Views: 327
Reputation: 141
Well it turned out that it was resulting in following structure only:- Type Action Actually to print the resulting element in docs i was using importFile.toString(). Instead of it printing as importFile.xmlText(), I found the actual result.
Upvotes: 0
Reputation: 1495
Try to put your text into a CDATA block:
<ImportFile Name="32201"><![CDATA[Type Action ]]></ImportFile>
As I know there isn't right way to preserve whitespaces in the XML
According to the Annotated XML Specification, whitespaces in attribute values are normalized by the XML processor.
This topic could also be useful for understanding parsing of whitespaces in the XML - What You Need to Know About Whitespace in XML
Upvotes: 1