Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML
Hi I want to iterate through this Xml file and want to fetch its children nodes value in an array C# wpf
 
<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 2-Sep-13 23:56pm
Edited 2-Sep-13 23:58pm
v2
Comments
^Mo^ at 3-Sep-13 6:10am
   
What have you tried yourself so far?
chandan0285 at 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,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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()
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 370
1 Gihan Liyanage 338
2 Vinay Mistry 160
3 ChauhanAjay 160
4 syed shanu 125
0 Sergey Alexandrovich Kryukov 9,021
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 3 Sep 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100