xml - C# How to traverse a subtree with recursion? -


i guess, have set first starting point want explore subtree, build recursive call.

example:

<realroot>   <node>     <desiredroot>       <rootchild/>         <nestedchild/>       <rootchild/>     </desiredroot>   </node>  </realroot> 

my goal iterate only:

<desiredroot>       <rootchild/>         <nestedchild/>       <rootchild/> </desiredroot> 

what's best solution in c# so?

if understand correctly: simple example display names , types of elements:

            var xmlstr = @"<realroot>   <node>     <desiredroot>       <rootchild/>       <nestedchild/>       <rootchild/>     </desiredroot>   </node>  </realroot>";             var xd = xdocument.parse(xmlstr);             var el = xd.root.element("node").descendants();             foreach (var x in el)                 console.writeline("{0} [{1}]", x.name, x.nodetype); 

print:

desiredroot [element] rootchild [element] nestedchild [element] rootchild [element] 

link: https://dotnetfiddle.net/bie0zi


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -