本文介绍了如何从XML字符串中读取XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的xml
This is my xml
<REPORT-FILE>
<INQUIRY-STATUS>
<INQUIRY>
<INQUIRY-UNIQUE-REF-NO>006f000026EGk88JJFS99115740</INQUIRY-UNIQUE-REF-NO>
<MBR-ID>NBF0000131</MBR-ID>
<REQUEST-DT-TM>30-06-2015 17:13:51</REQUEST-DT-TM>
<REPORT-ID>CAPR161018CR40279043</REPORT-ID>
<RESPONSE-DT-TM>18-10-2016 11:23:25</RESPONSE-DT-TM>
<RESPONSE-TYPE>ACKNOWLEDGEMENT</RESPONSE-TYPE>
</INQUIRY>
</INQUIRY-STATUS>
</REPORT-FILE>
我的尝试:
What I have tried:
XmlDocument doc = new XmlDocument();
doc.LoadXml(dataPacket);
//root of the xml <DATAPACKET>
XmlElement root = doc.DocumentElement;
//using xpath to get data I want https://msdn.microsoft.com/en-us/library/ms256115%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
PacketRequestId = Int32.Parse(root.SelectSingleNode("@REQUEST-ID").InnerText);
PacketReferenceNumber = Int32.Parse(root.SelectSingleNode("@REFERENCE-NO").InnerText);
XmlNode responseType = root.SelectSingleNode(@"HEADER/RESPONSE-TYPE");
HeaderResponseTypeCode = Int32.Parse(responseType.SelectSingleNode("@CODE").InnerText);
HeaderResponseTypeDescription = responseType.SelectSingleNode("@DESCRIPTION").InnerText;
推荐答案
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlstring);
XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("REPORT-FILE/INQUIRY-STATUS/INQUIRY");
foreach (XmlNode node in nodeList)
{
string nodevalue= node.SelectSingleNode("INQUIRY-UNIQUE-REF-NO").InnerText;
}
{
这篇关于如何从XML字符串中读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!