我有以下XML:如何獲取c#中的父節點文本值?
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
</catalog>
我發現一個名爲 「三更雨」 的稱號。現在我想知道誰是他的父母,以便我可以使用<author>
文本節點。我想是這樣的:
var xpath = "../*[local-name() != 'title']";
xml.Load(xmlalltext);
var xl1 = xml.SelectNodes(xpath);
MessageBox.Show(xl1.Item(0).InnerText.ToString());
我只是字符串「午夜雨」,我想搜索他的作者。我的確瞭解你的代碼的邏輯。謝謝! –