Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list of XPaths and I wish to get collection of all nodes from one node to the next. I am using HTML Agility Pack, but I suspect that any correct XPathQuery will work regardless of the specific package being used.

C#
for (int i = 1; i < lXPaths.Count; i++)
{
    string sXPathQuery = ????;  // perhaps some string using lXPath[i-1] & lXPath[i] 
    HtmlNodeCollection nTopic = htmDoc.DocumentNode.SelectNodes(sXPathQuery);
    .
    .
    .
}


List of XPaths, lXPaths
[0]	"/body[1]/h1[1]"
[1]	"/body[1]/h1[2]"
[2]	"/body[1]/h2[1]"
[3]	"/body[1]/h2[2]"
[4]	"/body[1]/h2[3]"
[5]	"/body[1]/h1[3]"
[6]	"/body[1]/h2[4]"
[7]	"/body[1]/h2[5]"
[8]	"/body[1]/h2[6]"
[9]	"/body[1]/h2[7]"
[10]	"/body[1]/h3[1]"
[11]	"/body[1]/h3[2]"
[12]	"/body[1]/h3[3]"
[13]	"/body[1]/h3[4]"
[14]	"/body[1]/h3[5]"
[15]	"/body[1]/h3[6]"
.
.
.
Posted
Updated 31-Dec-15 13:08pm
v2
Comments
PIEBALDconsult 31-Dec-15 18:59pm    
Yes.

How about a brief example of input and output?
snavece 1-Jan-16 13:53pm    
The input is any arbitrary HTML document from MS Word, that I am splitting up into topics for a chm help file. My intent is to write out the resulting collection of nodes with some additions (<html, ... </header>, <body, the collection of nodes </html>.
snavece 1-Jan-16 17:51pm    
The list of XPaths have every h1, h2 and h3.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900