Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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;
Posted
Updated 19-Oct-16 19:49pm
v4
Comments
[no name] 19-Oct-16 8:47am    
What do you mean "how to read this"? Unless you have a problem with your code, the answer is, just like you are doing.
Vikram Singh Rathaur 19-Oct-16 9:01am    
I just want to read data from xml file.
[no name] 19-Oct-16 9:12am    
Okay so go ahead and do that. We can't read your mind to know what your problem might possibly be.
F-ES Sitecore 19-Oct-16 8:53am    
What you've posted isn't valid XML, also there is little correlation between what you've posted and the code.
Vikram Singh Rathaur 19-Oct-16 9:01am    
I just want to read data from xml file.

C#
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;
}
                        {
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900