0

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!

Josh
  • 37
  • 5
  • ReadInnerXml() is what I'm using but it automatically converts the reference to the character. I'm hoping there may be something in XmlReaderSettings but not finding anything at the moment. – Josh Mar 31 '20 at 11:06
  • You can't send an apostrophe in a xml file so you must convert to ' See wiki : https://en.wikipedia.org/wiki/Character_encodings_in_HTML – jdweng Mar 31 '20 at 11:18
  • @jdweng that's quite incorrect. A literal apostrophe in XML does not need to be escaped, and in any case `'` isn't available as a built-in entity. Your reference is to HTML, not to XML. – Michael Kay Mar 31 '20 at 13:10
  • @Michael Kay : Read the link : 'XML character references' – jdweng Mar 31 '20 at 13:52
  • OK, I was half wrong (but you were completely wrong). `'` is always available in XML, but it is never needed, because the plain apostrophe character is valid in all contexts except an attribute value delimited by apostrophes (which are rare and avoidable). – Michael Kay Mar 31 '20 at 15:41

1 Answers1

1

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.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • That's what I'd thought, unfortunately there's no getting around it as far as changing the process goes, thank you! – Josh Mar 31 '20 at 14:02