Posted by: R Manimaran | April 18, 2007

XML and XPath in C#

XML Concepts

  • XML – Extensible Markup Language, describe data structures in text format and with your own vocabularies, which means it does not use predefined tags and the meaning of these tags are not well understood.
  • XSL – Extensible Stylesheet Language, is designed for expressing stylesheets for XML documents. XSL is to XML as CSS is to HTML.
  • XML Transformation – is a user-defined algorithm that transforms a given XML document to another format, such as XML, HTML, XHTML. The algorithm is described by XSL.
  • XSLT – is designed for use as part of XSL, transforming an XML document into another XML document, or another type of document that is recognized by a browser, like HTML or XHTML. XSLT uses XPath.
  • XPath – is a set of syntax rules for defining parts of an XML document.

Sample XML File: Employees.xml <Employees><Employee id=1/><Employee id=2/><Employee id=2/></Employees> 

C# Program XmlDocument doc=new XmlDocument();

doc.Load(“Employees.xml”);

XmlNodeList nodes;

int ID=0;

nodes=doc.SelectNodes(“//Employees/Employee[not(@id <=preceding-sibling::Employee/@id) and not(@id <=following-sibling::Employee/@id)]”);   

  for(int i=0;i<nodes.Count;i++)

{

  XmlAttributeCollection  coll=nodes[i].Attributes;                                                                                                             nNodeID=Convert.ToInt32(coll[0].Value);       

   }

Here nNodeID gives the Maximum of the Employee id. i..e 3 here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: