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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -