0
我想從我的xml文件中獲取屬性。該屬性在我的根上。看到這裏的一個例子:如何使用XPathNavigator從xml文件的根中獲取屬性?
<PriceList ID="003" xmlns="BLA">
<Items>
<Item ID="AAK0435">
<RetailPrice currency="EUR">1.6</RetailPrice>
</Item>
<Item ID="AAL0144">
<RetailPrice currency="EUR">1470</RetailPrice>
</Item>
</Items>
</PriceList>
我想獲得屬性「ID」的根。我嘗試了這樣的事情,但他並沒有進入foreach循環。
XPathDocument xPriceDocument = new XPathDocument(priceList.FullName, XmlSpace.None);
XPathNavigator xPriceNavigator = xPriceDocument.CreateNavigator();
foreach (XPathNavigator xPriceListIdNavigator in xPriceNavigator.Select("PriceList"))
{
priceListId = xPriceListIdNavigator.GetAttribute("ID", "");
}