Trim() the values of all xml elements and attributes in an xml document using c# -


i'm trying figure out simplest way take xml this:

<car>  <description model="ford      ">blue     </description> </car> 

into this:

<car>   <description model="ford">blue</description> </car> 

using linq xml, how like:

foreach (var element in doc.descendants()) {     foreach (var attribute in element.attributes())     {         attribute.value = attribute.value.trim();     }     foreach (var textnode in element.nodes().oftype<xtext>())     {         textnode.value = textnode.value.trim();     }     } 

i think should work... don't believe need use tolist avoid disturbing things iterate, you're not changing structure of xml document, text.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -