Reputation: 4740
I'm trying to read a XML file, but I want to know just the name of the node
and her value.
Example
<User>
<Contact>
<Name>Lucas</Name>
<ID>123</ID>
</Contact>
</User>
I'm trying use this code below but without success. How can I return just the node
name and her value ?
foreach (var name in doc2.Root.DescendantNodes().OfType<XNode>().Select(x => x).Distinct())
{
string nome = name.ToString();
}
I want that my string receives the name of my Node, is this case will be Name
and her value, that will be Lucas
Upvotes: 0
Views: 69
Reputation: 887453
foreach(var element in doc2.Root.Descendants()) {
String name = element.Name.LocalName;
String value = element.Value;
}
Upvotes: 3