EDIT as noted by @Gaim, my original version failed to capture a terminal dt
string xml = @"
<root>
<dt>name</dt>
<dd>value</dd>
<dt>name2</dt>
<dt>name3</dt>
<dd>value3</dd>
<dt>name4</dt>
<dt>name5</dt>
<dd>value5</dd>
<dt>name6</dt>
</root>
";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNodeList nodes =
doc.SelectNodes("//dt[not(following-sibling::*[1][self::dd])]");
foreach (XmlNode node in nodes)
{
Console.WriteLine(node.OuterXml);
}
Console.ReadLine();
Output is those dt
nodes that do not have a dd
immediately following them:
<dt>name2</dt>
<dt>name4</dt>
<dt>name6</dt>
What we are doing here is saying:
//dt
All dt
nodes, anywhere....
[not(following-sibling::*[1]
....such that it's not the case that their first following sibling (whatever it is called)....
[self::dd]]
...is called dd
.