Blog

Read Top 10 XMLNode

Posted by Rahul Kumar Saxena Blogs | XML Jul 20, 2010
Read numbers of XMLNode from an XML file.

Suppose Your EmployeeRecord.xml look like

<?xml version="1.0" encoding="utf-8" ?>
<Employees>
  <Employee>Ram</Employee>
  <Employee>Mohan</Employee>
  <Employee>Steve</Employee>
  <Employee>Allen</Employee>
  <Employee>Mike</Employee>
  <Employee>Alex</Employee>
  <Employee>Shyam</Employee>
  <Employee>Guru</Employee>
  <Employee>Aman</Employee>
  <Employee>Amit</Employee>
  <Employee>Ajit</Employee>
  <Employee>Mohit</Employee>
  <Employee>Sara</Employee>
</Employees>

And You want to read only top 10 Employee Records...

XmlDocument xmlDoc = new XmlDocument();
string FileName = Server.MapPath("EmployeeRecord.xml");
xmlDoc.Load(FileName);
XmlNodeList xnList = xmlDoc.SelectNodes("/Employees/Employee[position() <= 10]");
foreach (XmlNode xn in xnList)
{
    Response.Write(xn.InnerText);
    Response.Write("</br>");
}


By using this it will print only top 10 node of EmployeeRecord.xml file, like...


Ram
Mohan   
Steve
Allen
Mike 
Alex
Shyam
Guru
Aman
Amit

COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.