Replace mixed content in XML (plain text + tags)



The program takes an xml that is mixture between html and custom tags. I want to replace this custom tag:



<replaceable />


With this:



Some text
<div>Other text</div>


The main problem is that any framework or library that I can use to properly handle XML (like LinqToXML or System.Xml) cannot get the whole content. If try like this:



// replaceable is an XElement for <replaceable />
// content is a string
replaceable.ReplaceWith(content)


It ends up all as escaped text, and is taken as the value for the XElement.


And if I try the XElement.Parse() method, like other questions here suggest, I lose the plain text at the beginning, and only the <div> remains.


Is there a way to do this kind of replacement without going all regex on it?


No comments:

Post a Comment