jonas rudzionis
jonas rudzionis

Reputation: 115

C# reading an xml file, node value returns as blank

So basically, working on a xml file, that looks like this:

...
<city id="thatstheid">
  <country id="anotherid"> VALUE </country>
</city>
...

and i read the stuff i need using:

XmlDocument doc;//let's say this is the file im reading

XmlNode cityNode = doc.DocumentElement.SelectSingleNode("city");
cityname = cityNode.Attributes["id"].Value;

XmlNode countryNode = cityNode.SelectSingleNode("country");
countryname = countryNode.Value;

The problem here being that

countryname = countryNode.Value;

brings back an empty value, even though there's something inside.

If i try to get any atributes from the inside like this :

countryname = countryNode.Attributes["id"].Value;

it works fine, so i don't know what's the problem.

Upvotes: 0

Views: 979

Answers (1)

James Joyce Alano
James Joyce Alano

Reputation: 703

Try InnerText

countryname = countryNode.InnerText;

Upvotes: 1

Related Questions