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

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 answer

  • answered 2020-03-31 13:12 Michael Kay

    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.