user34537
user34537

Reputation:

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 0x2F, 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#?

Upvotes: 0

Views: 866

Answers (2)

manojlds
manojlds

Reputation: 301147

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;

Upvotes: 2

Matthew Flaschen
Matthew Flaschen

Reputation: 284796

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.

Upvotes: 7

Related Questions