从xpathnavigator中提取xml属性值

时间:2013-05-23 17:47:53

标签: c# xml

我试图通过以下代码获取基于州名的州代码:

        XPathDocument document = new XPathDocument("D:/Sample.xml");
        XPathNavigator navigator = document.CreateNavigator();
        XPathNavigator node =  navigator.SelectSingleNode("//WorldCountry/Country/states/states[@name='Maharastra']");
        string statescode=node.Attributes.GetNamedItem("code").Value

But I am getting error in list line saying that "**XPathNavigator** does not contain a defination of **Attributes**"

1 个答案:

答案 0 :(得分:0)