XML读取节点值
得到一个XML字符串,但不保存为.XML本地文件,但又要读取节点的值
如:
string param = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "+
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"+
"<soapenv:Body>"+
"<orderRelationUpdateNotifyReq xmlns=\"http://sp.ismp.chinatelecom.com\">"+
"<ns1:OPType xmlns:ns1=\"http://req.sp.ismp.chinatelecom.com\">0</ns1:OPType>"+
"<ns2:packageID xmlns:ns2=\"http://req.sp.ismp.chinatelecom.com\" />"+
"<ns3:productID xmlns:ns3=\"http://req.sp.ismp.chinatelecom.com\">119000000000000008557</ns3:productID>"+
"<ns4:streamingNo xmlns:ns4=\"http://req.sp.ismp.chinatelecom.com\">000000000000000000000000201007071621060100000000000000825509</ns4:streamingNo>"+
"<ns5:userID xmlns:ns5=\"http://req.sp.ismp.chinatelecom.com\">18973126226</ns5:userID>"+
"<ns6:userIDType xmlns:ns6=\"http://req.sp.ismp.chinatelecom.com\">0</ns6:userIDType>"+
"</orderRelationUpdateNotifyReq>"+
"</soapenv:Body>"+
"</soapenv:Envelope>";
string struserID = 要得到ns5:userID 的值?
我没写完,请高手指点
Stream ReStream = this.Request.InputStream;//接收传入的流数据
StreamReader read = new StreamReader(ReStream, Encoding.UTF8);
string content = read.ReadToEnd();
XmlDocument xmldoc = new XmlDocument();//实例化一个XmlDocument对像
xmldoc.LoadXml(content);//加载为xml文档
XmlElement root = xmldoc.DocumentElement;
string name = root.SelectSingleNode("???这里怎么写").InnerText;
------解决方案--------------------root.SelectSingleNode("/soapenv:Body/ns5:userID")
------解决方案--------------------XmlDocument doc = new XmlDocument();
doc.LoadXml("");
XmlNode temp = doc.SelectSingleNode("soapenv:Envelope/soapenv:Body/LogoutResponse/code");
string s = temp.InnerText;
------解决方案--------------------如果root是soapenv:Envelope这个节点。那么
string name = root.SelectSingleNode("./soapenv:Body/orderRelationUpdateNotifyReq/ns5:userID").InnerText;