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

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -