我有一个格式如下的 XmlDocument。如果我执行以下搜索
XmlNode title = xmlDoc.SelectNodes("//Book/Title[contains(., \"Title3\")]");
我将取回一个 XmlNode,它是一个标题。我如何确定该书是否属于出版物?我并不总是想假设 title.ParentNode.ParentNode.ParentNode 存在。应该有一种直观的说法:
if(title.hasAncestor("Publication") != null)
{
// do whatever
}
任何帮助将不胜感激
<Publications>
<Novel>
<Book>
<Title>Title1</Title>
<Author>Author1</Author>
<Year>2000</Year>
</Book>
<Book>
<Title>Title2</Title>
<Author>Author2</Author>
<Year>2000</Year>
</Book>
</Novel>
<History>
<Book>
<Title>Title3</Title>
<Author>Author3</Author>
<Year>2000</Year>
</Book>
<Book>
<Title>Title4</Title>
<Author>Author4</Author>
<Year>2000</Year>
</Book>
</History>
</Publications>
<StudyGuides>
<Math>
<Book>
<Title>Title5</Title>
<Author>Author5</Author>
<Year>2000</Year>
</Book>
<Book>
<Title>Title6</Title>
<Author>Author6</Author>
<Year>2000</Year>
</Book>
</Math>
<Science>
<Book>
<Title>Title7</Title>
<Author>Author7</Author>
<Year>2000</Year>
</Book>
<Book>
<Title>Title8</Title>
<Author>Author8</Author>
<Year>2000</Year>
</Book>
</Science>
</StudyGuides>