获取XML中的值
在一个项目中,厂商返回的接口信息是这样的:
<? xml version = "1.0" encoding = "utf-8" ?> < response > < message > Successfully created stockout order information </ message > < deliveryOrderId > CKDD0205200326000002 </ deliveryOrderId > < createTime > 2020 - 03 - 26 09:04:34 </ createTime > < flag > success </ flag > < code > 201 </ code > </ response >
XDocument xdoc = XDocument.Load(new StringReader(rr));
XElement root = xdoc.Elements().First();
string message = root.Element("message").Value;
string code = root.Element("code").Value;
string flag = root.Element("flag").Value;
string createTime = root.Element("createTime").Value;
string deliveryOrderId = root.Element("deliveryOrderId").Value;
----------------------------------------------------------------------------------------------------------------------------------------
方法二:
XmlDocument doc = new XmlDocument(); doc.InnerXml = rr;//rr是厂商返回的接口信息 直接加载到XMLDOcument中 string flag = doc.SelectSingleNode("response/flag").InnerXml; string code = doc.SelectSingleNode("response/code").InnerText; XmlNode xddoc = doc.SelectSingleNode("response/items"); string items = xddoc.InnerXml;
人各有命,上天注定,有人天生为王,有人落草为寇。脚下的路,如果不是你自己的选择,那么旅程的终点在哪,也没人知道。你会走到哪,会遇到谁,都不一定。