Delete an inner node but not the value in xml with XDocument library in C# .NET

后端 未结 2 578
Happy的楠姐
Happy的楠姐 2021-01-22 23:14

I have the following XML file:



  
    

Add<

2条回答
  •  [愿得一人]
    2021-01-22 23:56

    Remark: Your XML looks like HTML-Code. HTML is not always a valid XML (see the BR-Tag:
    ). 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(@"]*>([\s\S]*?)]*>");
    spanRegex.Replace(input, match => { return match.Groups[1].ToString(); });
    

    (see http://regexr.com/3cjuq)

提交回复
热议问题