Empty all XML-nodes of a certain type using C# -
i have xml document built using following structure:
<a> .... <b> <c> </c> <d> .... </d> </b> </a> <a> ....
i parse xml document using c# , output document in b-nodes emptied, without losing b-node. creating following result:
<a> ... <b /> </a> <a> ...
can show me way this?
linq xml make pretty simple:
var doc = xdocument.load(...); var bs = doc.descendants("b").tolist(); foreach (var b in bs) { b.replacenodes(); }
(use replaceall
instead of replacenodes
if want remove attributes within b
nodes well.)
Comments
Post a Comment