使用xmlnode读取xml文件的属性

时间:2012-10-15 20:34:11

标签: c# xmldocument

我正在尝试使用xml节点读取属性。但是我无法读取它。我正在做一些事情,但我无法弄清楚。我的xml文件看起来像这样.. Xml File

我试图读取InterfaceRequestID和InterfaceName,这是我的代码..

if (fPortalGuid != string.Empty)
                {
                    HttpWebRequest request = WebRequest.Create("http://cramapp-dt-02s.cable.comcast.com:8158/restfulqueryservice/queryservice/getrequestdetails?api_key=hiding key&request_id=33ebc6e9-9def-4f39-adf9-bba2edef3b54") as HttpWebRequest;
                    request.Method = "POST";

                    using (Stream stm = request.GetRequestStream())
                    {
                        using (StreamWriter stmw = new StreamWriter(stm))
                        {
                            stmw.Write(soap);
                        }
                    }
                    // Get response  
                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        // Get the response stream  
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                        // Console application output  
                        string result = reader.ReadToEnd();
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(result);
                        XmlNodeList radiusdns_nodelist;
                        XmlNodeList request_nodelist;
                        XmlNodeList fqdn_nodelist;
                        radiusdns_nodelist = xmlDoc.SelectNodes("/RADIUSDNSQueryResponsePayload");
                        request_nodelist = xmlDoc.SelectNodes("/RADIUSDNSQueryResponsePayload/request");
                        fqdn_nodelist = xmlDoc.SelectNodes("/RADIUSDNSQueryResponsePayload/request/fqdn");
                        string strInterfaceID = string.Empty, strInterfaceName = string.Empty;
                        if (radiusdns_nodelist.Count > 0)
                        {
                            foreach (XmlNode main_node in radiusdns_nodelist[0].ChildNodes)
                            {
                                strInterfaceID = main_node.Attributes["InterfaceRequestID"].Value;
                                strInterfaceName = main_node.Attributes["InterfaceName"].Value;
                            }
                        }
                    }
                }

我无法获取属性。我做错了什么?

0 个答案:

没有答案