How to get attribute value using SelectSingleNode?

后端 未结 3 1144
野的像风
野的像风 2021-01-11 09:19

I am parsing a xml document, I need find out the gid (an attribute) value (3810).

Based on SelectSingleNode(). I found it is not easy to find the attri

3条回答
  •  时光说笑
    2021-01-11 09:58

    You can query XmlDocument itself not DocumentRoot:

    XmlDocument doc = new XmlDocument();
    XmlNode book = doc.SelectSingleNode("..");
    if (book != null)
    {
        XmlAttribute gid = book.Attributes["gid"];
        if (gid != null)
        {
           string value = gid.Value;
        }
    }
    

提交回复
热议问题