Hai Tran
Hai Tran

Reputation: 107

How to read xml node contains ":"

I have a xml file for example:

<item>
<name>John Caters</name>
<age>46</age>
<cd:creator>Wings Man</cd:creator>
</item>

And i use (string)item.Element("name").Value to get content between <name> and </name>

but, i don't know how to get beween and

the're a problem width ":" in xml node

Upvotes: 0

Views: 408

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502406

That shouldn't be the full XML file. There should be something specifying what the namespace alias "cd" actually means, e.g.

<doc xmlns:cd="http://something">
  <item>
    ..
    <cd:creator>...</cd:creator>
  </item>
</doc>

At that point it's easy:

XNamespace cd = "http://something";
string creator = (string) item.Element(cd + "creator");

... but you do need to know the namespace URL first.

Upvotes: 4

Related Questions