简体   繁体   English

XDocument.Load()在xml文档中具有特殊字符

[英]XDocument.Load() with special character in xml document

I know google is full of this, but I couldn't make it work after hours of trying. 我知道google充满了这些,但是经过数小时的尝试后我无法使它正常工作。

So here's foo.xml: 所以这是foo.xml:

<Root>
    <Child>a</Child>
</Root>

XDocument.Load("foo.xml") works great. XDocument.Load(“ foo.xml”)很好用。

Here is bar.xml: 这是bar.xml:

<Root>
    <Child>á</Child>
</Root>

XDocument.Load("bar.xml") throws a System.Xml.XmlException: XDocument.Load(“ bar.xml”)引发System.Xml.XmlException:

{"Invalid character in the given encoding. Line 2, position 9."} {“给定编码中的无效字符。第2行,位置9。”}

How should I progress? 我应该如何进步?

这里没有魔术,我只需要将xml编码为UTF8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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