У нас есть абсолютно огромный справочный документ, созданный в Word, и он был использован для создания еще более массивного и громоздкого документа HTM. Используя C# и эту библиотеку, я хочу захватить и отобразить только один раздел этого файла в любой точке моего приложения. Разделы разбиты следующим образом:
<!--logical section starts here -->
<div>
<h1><span style='mso-spacerun:yes'></span><a name="_Toc325456104">Section A</a></h1>
</div>
<div> Lots of unnecessary markup for simple formatting... </div>
.....
<!--logical section ends here -->
<div>
<h1><span style='mso-spacerun:yes'></span><a name="_Toc325456104">Section B</a></h1>
</div>
Логически говоря, есть H1
с именем раздела в теге a
. Я хочу выбрать все из внешнего содержащего div, пока не столкнусь с другим h1
и исключить этот div.
под тегом h1
, который имеет несколько дочерних элементов (около 6 каждый)Моя попытка:
var startNode = helpDocument.DocumentNode.SelectSingleNode("//h1/a[contains(., '"+sectionName+"')]");
//go up one level from the a node to the h1 element
startNode=startNode.ParentNode;
//get the start index as the index of the div containing the h1 element
int startNodeIndex = startNode.ParentNode.ChildNodes.IndexOf(startNode);
//here I am not sure how to get the endNode location.
var endNode =?;
int endNodeIndex = endNode.ParentNode.ChildNodes.IndexOf(endNode);
//select everything from the start index to the end index
var nodes = startNode.ParentNode.ChildNodes.Where((n, index) => index >= startNodeIndex && index <= endNodeIndex).Select(n => n);
Поскольку я не смог найти документацию по этому вопросу, я не знаю, как я могу перейти от моего начального узла к следующему элементу h1 . Мы ценим любые предложения.