Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to iterate through this Xml file and want to fetch its children nodes value in an array C# wpf

XML
<UDK>
  <Gesture_0>Y + U</Gesture_0>
  <Gesture_1>N + B + M</Gesture_1>
  <Gesture_2>H + J</Gesture_2>
  <Gesture_3>B + V + N</Gesture_3>
  <Gesture_4>E + T</Gesture_4>
  <Down>L</Down>
</UDK><pre></pre>


e.g. in
array[0]=Y+U
array[1] = N+B and so on;
Posted
Updated 2-Sep-13 23:58pm
v2
Comments
Maarten Kools 3-Sep-13 6:10am    
What have you tried yourself so far?
chandan0285 3-Sep-13 6:22am    
I tried to use Xml reader but could not retrieve the value, I googled but could not find the right solution,

It's easy to do so with LINQ to XML. Parse the xml in an XElement[^] instance, and use the Elements()[^] method to loop through the child elements. From there you can fill an array.
 
Share this answer
 
Try the following code 
string xml = @"<UDK>
               <Gesture_0>Y + U</Gesture_0>
               <Gesture_1>N + B + M</Gesture_1>
               <Gesture_2>H + J</Gesture_2>
               <Gesture_3>B + V + N</Gesture_3>
               <Gesture_4>E + T</Gesture_4>
               <Down>L</Down>
               </UDK>";

XDocument document = XDocument.Parse(xml);

var result = document.XPathSelectElements(@"*/*").Select(e => e.Value).ToArray()
 
Share this answer
 
v2

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