开发者

How do i search XML when / is in it? C#?

I get this error with the code

var ff = from files in doc.Descendants("blah/Files") select files;

The error is

The '/' character, hexadecimal value 开发者_StackOverflow0x2F, cannot be included in a name.

In <Files> there are

<File id="f8" name="/usr/include/_G_config.h"/>

Now i cant change the XML and i need to access everything in it. How do i do that in C#?


The parameter to Descendants must be an XName (which can be implicitly converted from a string), which represents an element or attribute name. These can not contain slashes. Depending on the full XML, you may just be able to use:

doc.Descendants("Files")

or you may need to add code.


You are trying it out like you would an XPath but it expects an XName and an XName cannot have a "/" in it

Instead you can directly do something like this:

var ff = from file in doc.Descendants("file") select file;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜