Is there a way to have an XmlReader preserve a character reference as text rather than converting it?

217 views Asked by At

I'm using an xml reader to parse some xml and I'm wondering if I can have it read in a character entity reference as straight text rather than converting it to the actual character. So if I called ReadInnerXml() on the node:

<param name="id">don&apos;t convert this</param> 

I would get "don&apos;t convert this" as opposed to what I'm currently getting, which is "don't convert this". This is necessary as any characters or character entity references should be handed back the way the came due to them being legacy content.

Any help appreciated!

1

There are 1 answers

1
Michael Kay On

No, I don't know of any XML parser that has this feature. The job of an XML parser is to parse the input, and that's what it will do.

If you can't fix the consumer of this process to handle XML properly, your best bet might be to preprocess the text by replacing & by (say) ยง so it doesn't mean anything special to the XML parser.