Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is my xml i need to read this xml and display in gridview with below columns 

Bnum    Pnum   Vnum    Bdilute   Cdilute   Test   Mcode and the data for that columns should be brought from below xml 

For Bnum we need to get SID from view1 tag of xml
For Pnum we need to get IDPa from view2 tag of xml
For Vnum we need to get ID from Act1 tag of xml
For Bdilute we need to get TrDate from view1 tag of xml
For Cdilute we need to get Code from Act1,Act2 and Act3 tag of xml
For Test we need to get Type from Dial1 tag of xml
For Mcode we need to get Co from Dial1 tag of xml



<SID>MOH-F-1000076</SID>  --required


<TrDate>13/03/2018 08:42</TrDate>  --required




<IDPa>5653584</IDPa>  --required




<Start>01/08/2017 00:09</Start>

<End>02/08/2017 19:48</End>



<Type>Principal</Type>  --required

<Co>K35.80</Co> --required



<Type>Secondary</Type>  --required

<Co>R10.9</Co>  --required


<Type>Secondary</Type>  --required

<Code>R11.0</Code>  --required



<Type>Secondary</Type>  --required
<Code>R63.8</Code>  --required



<Type>Secondary</Type>   --required

<Code>R79.89</Code>  --required



<Type>Secondary</Type>  --required

<Code>Z01.812</Code>  --required



<Type>Secondary</Type>  --required

<Code>Z01.83</Code>  --required



<ID>1</ID>    --required

<Code>36000</Code>  --required



<ID>2</ID>  --required

<Code>85396</Code>  --required



<ID>3</ID>  --required

<Code>86900</Code>  --required



What I have tried:

can anyone help us out as we are unable to retrieve them
Updated 13-Mar-18 23:48pm
F-ES Sitecore 14-Mar-18 5:35am    
You're going to have to convert your XML into a list of objects that hold the data you want. To find out how to do this google "c# deserialise xml". If the xml is dynamic, in that you don't know how many "act" or "dial" nodes there are then basic deserialisation might not work, instead you might have to just parse the data yourself to extract what you need (google "c# custom xml deserialisation"). Once the data is in a List or of objects you can then bind that to your gridview.

Please don't ask me to write the code for you, this is not a code-writing service, look into the various things I've mentioned above and at least attempt the code yourself.
Laxmidhar tatwa technologies 14-Mar-18 6:48am    
If u stored it in a file
Use namespace system.XML
Xmldocument doc = new xmldocument();
doc.load(XML file path);
In for each loop get each node
Then get the value of each node and subnode
kav@94 14-Mar-18 6:53am    
That is what i am unable to get it i was already trying in the same way
Laxmidhar tatwa technologies 14-Mar-18 7:49am
kav@94 14-Mar-18 7:58am    
below is the code which i have tried as suggested by you
XmlDocument Docs = new XmlDocument();
XmlElement root = Docs.DocumentElement;
DataTable dt = new DataTable();
XmlNodeList nodes = root.SelectNodes("????????");
foreach (XmlNode node in nodes)
return dt;
catch (Exception es)
throw es;
but it is going into catch block and giving me the exception object reference not set to instance of object.I am unable to get how to provide the relation in this line XmlNodeList nodes = root.SelectNodes("????????"); to get the value of get the value of each node and subnode

1 solution

Have you looked at the following article XML Reader?
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