Explicit Element Closing Tags with System.Xml.Linq Namespace

前端 未结 4 1816
既然无缘
既然无缘 2020-12-20 20:32

I am using the (.NET 3.5 SP1) System.Xml.Linq namespace to populate an html template document with div tags of data (and then save it to disk). Sometimes the div tags are e

相关标签:
4条回答
  • 2020-12-20 20:54

    I'm not sure why you'd end up with an empty DIV (seems a bit pointless!) But:

    divTag.SetValue(string.Empty);
    

    Should do it.

    0 讨论(0)
  • 2020-12-20 21:01

    I don't know the answer to your question using LINQ. But there is a project called HTML Agility Pack on codeplex that allows you to create and manipulate HTML documents much similar to the way we can manipulate XML document using System.Xml namespace classes.

    0 讨论(0)
  • 2020-12-20 21:01

    I did this. Working as expected.

    myXml = new XElement("script", new XAttribute("src", "value"));
    myXml .Value = "";
    

    Which gives below as result.

    <script src = "value"></script>
    
    0 讨论(0)
  • 2020-12-20 21:06

    With XElement divTag = new XElement("div", String.Empty); you get the explicit closing tag

    0 讨论(0)
提交回复
热议问题