c# - How to iterate to the next sibling xml element? -
consider have following xml structure:
<root> <file> a.txt <version> 1.5 </version> </file> <file> b.txt <version> 1.0 </version> </file> </root> if hold variable holds element :
<file> a.txt <version> 1.5 </version> </file> how can handle next element is:
<file> b.txt <version> 1.0 </version> </file> i've been trying couple of things such xelement.nextnode() got null instead of reasonable handle
you use elementsafterself:
var nextelement = currentelement.elementsafterself("file").firstordefault(); if (nextelement != null) { ... } alternatively, try refactor code can use loop on elements start with:
foreach (var fileelement in parentelement.elements("file")) { ... } (in both cases can omit element name if want next element, whatever is.)
Comments
Post a Comment