Reputation: 201
I have an XML like:
<Employee>
<Name> XXXX </Name>
<Address> YYYY </Addeess>
<Country> ZZZZ </Country>
</Employee>
How can i get the inner value of Country? Here Country is dynamically generated(based on user input).
It may be present or not. If present i need to fetch the inner value using c#.
Upvotes: 0
Views: 1217
Reputation: 648
This may help you :
XmlDocument ob = new XmlDocument();
ob.Load("yourxmlfile.xml");
XmlNodeList obj_country = ob.GetElementsByTagName("Country");
if(obj_country!= null)
{
string innertext_country_node = obj_country[0].InnerText;
}
Upvotes: 3
Reputation: 75316
var countryElement = XElement.Parse(xml).Element("Country");
string result = (countryElement != null) ? countryElement.Value : string.Empty;
Upvotes: 1