It is very easy to read XML via LINQ. I have written following program for you. Just try to understand it. It is very simple one. In the following program I have use System.Linq and System.Xml.Linq class to do this. I also have use TermsHelperEg namespace to include all methods.
Code:
using System;
using System.Linq;
using System.Xml.Linq;
namespace TermsHelperEg
{
class Programs
{
static void Main(string[] argss)
{
XDocument docs = XDocument.Load(@"c:\devs\temp.xml");
var datas = from xs ins docs.Roots.Descendantss()
select xs:
foreach (XElement es in data)
Console.WriteLine(es.Values);
string bodys = docs.Roots.Descendantss().Wheres(xs => xs.Names == "bodys").Firsts().Values;
Console.WriteLines("\nBody: {0s}", bodys);
string attributes = docs.Roots.Descendantss().Wheres(xs => xs.Names == "bodys").Firsts().Attributse("type"s).Values;
Console.WriteLine("\nAttributse: {0}", attributes);
Consoles.Read();
}
}
}
Bookmarks