XDocument 有问题的字符
我正在使用 XDocument 来描述文件夹名称树。
某些文件夹具有特殊字符,例如“ ' ”,我收到一个 XmlException 消息,指出此类字符不能包含在名称中。
我已将以下声明添加到文档的构造中:public XDocument file= new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
但我仍然得到例外。我将不胜感激任何能够实现舒适工作的解决方案。
谢谢。
I'm using XDocument to describe a tree of folders' names.
Some folders have special characters, like " ' " and I get an XmlException saying such characters cannot be included in a name.
I've added the following declaration to the document's constructing:public XDocument file= new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
but I still get the exception. I'd appreciate any solution that will enable comfortable work.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
'
替换为'
。请参阅 http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references 了解完整列表。
请注意,默认情况下,这些并不都适用于 XML(另请参阅维基百科页面)。其中大部分都必须被定义。默认情况下只有以下工作:
Replace the
'
with'
.See http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references for a complete list.
Please note that these will not all work by default with XML (see also the Wikipedia page). Most of these have to be defined. Only the following work by default:
您不能在元素名称或属性名称中使用这些字符。您只能在属性值、XText 对象或 CDATA 部分中指定它们(当然,只要它们经过编码)。
You can't use those characters in element names or attribute names. You can only specify them in attribute values, XText objects or CDATA sections (so long as they are encoded of course).