Tuesday, 3 February 2015

XElement Replacement when Child Elements and Value Exist



I have some Xml that I am trying to change the name of the XElement on. The XElement contains both child elements and a value similar to this



<parent>
Hi I am a value <a href="link">link</a>
</parent>


I tried using the method suggested here but i can only copy either the elements or the value. Setting the elements first and then the value wipes out the elements.



<newparent>
Hi I am a value link
</newparent>


Copying the value and then elements duplicates the element text



<newparent>
Hi I am a value link <a href="link">link</a>
</newparent>


String manipulation of the value itself escapes all of the brackets.



<newparent>
Hi I am a value link &lt;a href="link"&gt;link&lt;/a&gt;
</newparent>


Does someone know of a way to achieve the result of copying the value and elements over to the newly created element correctly?


No comments:

Post a Comment