我想从我的 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", "");
}