简体   繁体   中英

Exception on XMLDocument.LoadXml only for specific iso characters

I am using Windows.Data.Xml.Dom.XmlDocument to parse an xml string.

The code is simple

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);

The problem is that it throws an exception when it encounters some specific characters. An example is below. (Yes the XML I am parsing is actually html but it has to be parsed as XML)

This string throws the exception

<div>So schnell. So vielf&auml;ltig. Soo lecker!</div>

These do not

<div>So schnell. So vielfltig. Soo lecker!</div>

<div>So schnell. So vielf&lt;ltig. Soo lecker!</div>

These are the message and type of the exception.
Exception from HRESULT: 0xC00CE002 System.Exception

I don't know why only specific characters trigger the exception. Can anybody help?

Xml does not support all html characters and the character you mentioned is an html character. Supported character list for xml and html : https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML

Xml only supports quot amp apos lt gt
You will have to use hex value of the other special characters in order for them to be loaded as xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM