开发者

XDocument problematic characters

开发者 https://www.devze.com 2023-01-26 01:21 出处:网络
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'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 declarat开发者_如何学编程ion 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.


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:

' => '
" => "
& => &
> => >
&lt; => <


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消