| In Below example we will read xml document in c# using linq. First i have created a xml file with below content
< ?xml version="1.0" encoding="utf-8" ?>
< websites xmlns="urn:websitename">
< websitename>getproductprice.com< /websitename>
< websitename>interviewqsn.com< /websitename>
< /websites>
To read above xml file we will write below code and name of abov file is websites.xml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace LinqExample
{
class websitename
{
static void Main(string[] args)
{
var doc = XDocument.Load("websites.xml");
var query = from x in doc.Descendants("{urn:websitename}websitename")
select x;
foreach (var item in query)
{
Console.WriteLine(item);
}
}
}
}
| | |