Symetric XML parsing and printing



I am looking for a way to parse and print (slighly changed) XML such that the content of elements stays unchanged, even if it contains escaped and unescaped greater than or less than signs (i.e. > as well as > or < and < ). SaxHandler returns a > or < character even if the source contained the escaped way of writing it. But I need to know, whether it was escaped or written as single sign.


Why do I need that: I like to keep my strings.xml file sorted by the name attribute. Therefore I am parsing the file, sort the string elements by the name attribute, and print it out again. Unfortunately a file which looks e.g. like that:



<resources>
<string name="B">--&gt;</string>
<string name="C">--></string>
<string name="A">&lt;--</string>
</resources>


is changed after parsing and sorting to:



<resources>
<string name="A"><--</string>
<string name="B">--></string>
<string name="C">--></string>
</resources>


where the string A contains invalid XML.


Is there an easy way, still using an standard XML parser, to get the raw content of an element.


No comments:

Post a Comment