0
我有一組數據xml節點列表,我想過濾一個特定的屬性內部文本,我試過這個,但沒有任何工作。我的代碼在這裏,也張貼的XML數據我如何過濾XmlNodeList
string baseName = categoryName.Split(':').Last();
int categoryId = 0;
string xmlFile = File.ReadAllText(Application.StartupPath + @"\EbayCategories\EbayCategories.xml");
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(xmlFile);
XmlNodeList nodeList = xmldoc.SelectNodes("/CategoryArray/Category[CategoryName='" + baseName + "']");
if (nodeList.Count > 0)
{
var memberNames = nodeList.Cast<XmlNode>().Where(node => node.Attributes["CategoryID"].InnerText == "58193").ToList();
categoryId = int.Parse(nodeList[0]["CategoryID"].InnerText);
}
這是我的xml數據。我想過濾CategoryParentID =我的價值。
<CategoryArray>
<Category>
<BestOfferEnabled>true</BestOfferEnabled>
<AutoPayEnabled>true</AutoPayEnabled>
<CategoryID>20081</CategoryID>
<CategoryLevel>1</CategoryLevel>
<CategoryName>Antiques</CategoryName>
<CategoryParentID>20081</CategoryParentID>
</Category>
<Category>
<BestOfferEnabled>true</BestOfferEnabled>
<AutoPayEnabled>true</AutoPayEnabled>
<CategoryID>37903</CategoryID>
<CategoryLevel>2</CategoryLevel>
<CategoryName>Antiquities</CategoryName>
<CategoryParentID>20081</CategoryParentID>
</Category>
<Category>
<BestOfferEnabled>true</BestOfferEnabled>
<AutoPayEnabled>true</AutoPayEnabled>
<CategoryID>37908</CategoryID>
<CategoryLevel>3</CategoryLevel>
<CategoryName>The Americas</CategoryName>
<CategoryParentID>37903</CategoryParentID>
<LeafCategory>true</LeafCategory>
</Category>
<Category>
<BestOfferEnabled>true</BestOfferEnabled>
<AutoPayEnabled>true</AutoPayEnabled>
<CategoryID>162922</CategoryID>
<CategoryLevel>3</CategoryLevel>
<CategoryName>Byzantine</CategoryName>
<CategoryParentID>37903</CategoryParentID>
<LeafCategory>true</LeafCategory>
</Category>
分享您的XML文件 –
看到更新後的問題 – Mehaboob