In my environment here I use Java to serialize the result set to XML. It happens basically like this:
//foreach column of each row xmlHandler.startElement(uri, lname, 'column', attributes); String chars = rs.getString(i); xmlHandler.characters(chars.toCharArray(), 0, chars.length()); xmlHandler.endElement(uri, lname, 'column');
The XML looks like this in Firefox:
<row num='69004'> <column num='1'>10069</column> <column num='2'>sd</column> <column num='3'>FCVolume </column> </row>
But when I parse the XML I get the a
org.xml.sax.SAXParseException: Character reference ‘‘ is an invalid XML character.
My question now is: Which charactes do I have to replace or how do I have to encode my characters, that they will be valid XML?
I found an interesting list in the Xml Spec: According to that List its discouraged to use the Character #26 (Hex: #x1A).
See the complete ranges.
This code replaces all non-valid Xml Utf8 from a String:
its taken from Invalid XML Characters: when valid UTF8 does not mean valid XML
But with that I had the still UTF-8 compatility issue:
After reading XML – returning XML as UTF-8 from a servlet I just tried out what happens if I set the Contenttype like this:
And it worked ….