How to load XML with special characters using XDocument.Load

自作多情 提交于 2019-12-25 01:33:28

问题


**This is for silverlight application.

I have a stream with xml data, which after loading massage the data and generate final file. I start by load using XDocument.Load(stream). One of the file was failing to load and after some research I foung out that one of the element has a value of 'First & Second' and load fails on hitting &.

Is it possible to load XML with special characters? ( I am sure the answer is no, but worth asking).

Is it possible to preprocess the XML (without performance hit) and change the special characters to someother characters and after the process put it back to normal value.


回答1:


In XML, & should be & otherwise it's not valid XML. If you don't have control over the XML files, load them as text, replace & with & in memory (but be careful not to replace the & that are part of entities like existing & > or < !) and load them as XML again.



来源:https://stackoverflow.com/questions/3017892/how-to-load-xml-with-special-characters-using-xdocument-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!