XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The following code illustrates how to extract XPath using HtmlAgilityPack and a webclient on the fly.
You need to add a reference for HtmlAgilityPack; I've used version 1.4.0.1.
You can refer to http://htmlagilitypack.codeplex.com/releases/view/44954 to download the .dll
In this article we have used it to get multiple nodes using SelectNodesByPattern, which is an extension method.
We've used this url (http://htmlagilitypack.codeplex.com/releases/view/44954) as shown in the browser and found the value of "1.4.0 Stable". 
We've tried to fetch a value of all heading "h1" tags having class ='page_title', kindly refer to the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using System.Net;
using System.IO;
namespace DescendantUsingXPath
{
public static class Program
{
static void Main(string[] args)
{
//WebClient object
WebClient x = new WebClient();
//Convert given url data to bytearray using DownloadData
byte[] byteArray = x.DownloadData(new Uri("http://htmlagilitypack.codeplex.com/releases/view/44954"));
//Convert Byte Array into Stram
Stream stream = new MemoryStream(byteArray);
//Create new object of HtmlAgilityPack.HtmlDocument
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
//To load stream into html object


Ravi PrakashPosted May 30, 2017, 2:55 AM
Foreach (HtmlNode node in doc.DocumentNode.Descendants()) { if (node.Name != "#text" && node.Name != "#comment") { Console.WriteLine(node.Name + " " + node.GetAttributeValue("Id", true)); string strValue = node.InnerText; Console.WriteLine(strValue); } } I used this get all the node and id of the node.But I also need to get the x path of each node and also the I should get CSS and Name attribute if they are present. hope u may guide me.Thanks in advance
Gagan SikriPosted Jul 24, 2015, 9:23 AM
Good One :)
Dinesh BeniwalPosted Jun 26, 2012, 6:59 AM
Good Start Sachin.
Lajapathy ArunPosted Jun 26, 2012, 6:31 AM
nice one :)