Using HTML Agility Pack, I am trying to select nodes in XHTML using XPATH. I want to select the children I listed below in each p tag, but not the grandchildren:
<strike></strike>
<em></em>
<u></u>
<strong></strong>
<sub></sub>
<sup></sup>
In other words, I'm looking for A and B, but not the second level of either nodes. Mean while, A or B nodes can be found anywhere in the set. Note: That A or B can be any of the ones I listed above.
If I have the following XHTML:
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 25 March 2009), see www.w3.org" />
<title></title>
</head>
<body>
<p><strike>element 1</strike> and <strike><em>element 2</em></strike></p>
<p><strike>element 3</strike></p>
<p><strike>element 4</strike></p>
</body>
</html>
If I can select the children I listed above in each p tag, it will return the following collection of nodes: strike, strike, strike and strike. Giving me access to the children of each strike.
<strike>element 1</strike> and <strike><em>element 2</em></strike>
The first in XPATH means sub [1]
(I mean instance of strike) and the second, which was ignored is sub [2]
(I mean instance of strike). This makes sense because that's what my query is doing. Then the XPATH grabs the <em>
tag and so on...
Another way I can explain this is by saying I want //a|//b|//c|//d|//e
and not the children. Is this possible?
In the end, this leaves me confused in how I can arrive to my solution.
I was looking at MSDN for answers on XPATH.
Please let me know if you need further research or information. I will provide it.
` tag wont show up. I wonder if I can force it to have that. The answer is useful, but its not the solution yet. I'm still looking for a better answer.
– Vyache Dec 12 '12 at 21:38element 1andelement 2` by selecting `//p/*`, although that would miss the text nodes. Also have a look here: http://stackoverflow.com/questions/1791108/xpath-expression-to-select-all-xml-child-nodes-except-a-specific-list – Frank van Puffelen Dec 13 '12 at 21:04