I am bit stuck in getting the values printed from the XML using XPath or LINQ also new to XPath and XML Parsing , Looked into couple of examples here but nothing helped as they all have XML with diffrent attribute names, For my case XML is diffrent :
<Entities TotalResult="3">
<Entity Type="test-set-folder">
<Fields>
<Field Name="id">
<Value>12457</Value>
</Field>
<Field Name="parent-id">
<Value>0</Value>
</Field>
<Field Name="last-modified">
<Value>2015-03-09 14:09:57</Value>
</Field>
<Field Name="description">
<Value/>
</Field>
<Field Name="view-order"/>
<Field Name="name">
<Value>.NET</Value>
</Field>
</Fields>
</Entity>
<Entity Type="test-set-folder">
<Fields>
<Field Name="id">
<Value>15487</Value>
</Field>
<Field Name="parent-id">
<Value>0</Value>
</Field>
<Field Name="last-modified">
<Value>2015-03-15 13:00:02</Value>
</Field>
<Field Name="description">
<Value/>
</Field>
<Field Name="view-order"/>
<Field Name="name">
<Value>Python</Value>
</Field>
</Fields>
</Entity>
</Entities>
It has same attribute Field
but different Name
.
Can Someone help me in printing the Name
of property and its Value
.
I need to iterate through each of the Entity and print its Name : Value
.
So far i Have tried using Xpath and LINQ both :
var doc = XDocument.Load("XMLFile1.xml");
foreach (var child in doc.Element("Field Name").Elements())
{
Console.WriteLine(child.Name);
}
But seriously i don't have much idea of it , so my approach is entirely wrong.
My Expected Output is :
Id: 12457
parent-id: 0
last-modified:2015-03-09 14:09:57
description:
view-order:
name: .NET
and same for the next entity .