I have the following XML file:
Add<
Remark: Your XML looks like HTML-Code. HTML is not always a valid XML (see the BR-Tag: <br>
). That might cause exceptions - so you either should be very sure that your HTML is a valid XML (then you can use XDocument
) or you should use Regex.Replace()
Regex spanRegex = new Regex(@"<span[^>]*>([\s\S]*?)</span[^>]*>");
spanRegex.Replace(input, match => { return match.Groups[1].ToString(); });
(see http://regexr.com/3cjuq)
Use ReplaceWith
, e.g.
XDocument doc = XDocument.Load("file.xml");
XElement span = doc.Descendants("p").First().Elements("span").FirstOrDefault(s => (string)s.Attribute("class") == "screenitems");
if (span != null)
{
span.ReplaceWith(span.Nodes());
}