c# - How to round-trip "invalid XML characters" - aren't character references valid/applicable? -


The following two code samples reflect this problem I am not decoding or decoding "invalid characters".

  var elm = new XElement ("foo", "\ x12") Elm ToString (); // ArgumentException: '', hexadecimal value 0x12, is an invalid character  

similarly, parsing

  var elm2 = XElement.Parse ("& lt ; Foo & gt; & amp; # x0012; & lt; / foo & gt; "); // XmlException: '', hexadecimal value 0x12, is an invalid character.  

This causes unexpected exceptions in unexpected cases -

How do I solve " "Is it such that XML is always encoded correctly without exception?

If I can preserve "invalid character" in these monsters, then there is a standard way of doing this without a custom encoding ( Like Base 64) Process?

Besides, I'm surprised to see that using an XML entity did not fix the problem - is not encoded? Is it OK to empty the invalid XML characters in this case, but is not willing to take action manually every < / Em> The text node is inserted into the XElement structure.

This is not just a XElement issue, although answers can rely on XElement, because online verification sites have also rejected XML in the second case.

<> There is no way to create a valid XML document with invalid characters that is approximately 0-31 for XML 1.0 and for XML 1.1 is just 0 (but System.Xml does not support this standard). The complete list can be found in the specification, or Wikipedia.

The recommended way to deal with such information, which is basically "binary data", is to encode base 64.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -