Escaping Unicode string in XmlElement despite writing XML in UTF-8

后端 未结 1 1136
天命终不由人
天命终不由人 2021-01-14 02:25

For a given XmlElement, I need to be able to set the inner text to an escaped version of the Unicode string, despite the document ultimately being encoded in UT

相关标签:
1条回答
  • 2021-01-14 03:18

    If you ask XmlWriter to produce ASCII output, it should give you character references for all non-ASCII content.

    var settings = new XmlWriterSettings {Encoding = Encoding.ASCII, OmitXmlDeclaration = true};
    

    The output is still valid UTF-8, because ASCII is a subset of UTF-8.

    0 讨论(0)
提交回复
热议问题