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]
Comments
Post a Comment