Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i retrieve data from the following xml file?

XML
<xml>
<data>
<timing>
<time-key>k-fkskdsj-23d</time-key>
<time>12.30</time>
<time>12.40</time>
<time>12.43</time>
</timing>

<timing>
<time-key>k-fkhhasw-36v</time-key>
<time>17.30</time>
<time>18.26</time>
<time>21.25</time>
</timing>
</data>
</xml>


> I want to get the data under data tag as per their respective time-key.
> Number of time tags may vary, above data is just for illustration.
Posted
Updated 16-Sep-13 0:53am
v2
Comments
abbaspirmoradi 16-Sep-13 6:55am    
same question:http://www.codeproject.com/Answers/647534/How-to-iterate-through-Xml-Child-node-and-get-ther#answer2

1 solution

C#
XmlDocument doc = new XmlDocument();
doc.Load(your xml document);
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
   if (node.Name == "time-key")
   node.InnerText;//This will give you k-fkskdsj-23d for first one
}

You can modify this as per the requirement.

Regards..:)
 
Share this answer
 
Comments
Shehzaada Salim 16-Sep-13 7:29am    
I want time data for it's respective time key.
Thanks7872 16-Sep-13 8:56am    
Don't you get idea how to access nodes in xml from the above code?

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