How to avoid System.Xml.Linq.XElement escaping HTML content?

前端 未结 4 1229
孤城傲影
孤城傲影 2020-12-18 03:36

I\'m using the XElement object to build some HTML in the code-behind on an ASP.NET page.

I may or may not add some XAttributes to this XElement as I go along, in the

4条回答
  •  臣服心动
    2020-12-18 04:19

     var elmnt = new XElement("div",
       new XAttribute("id", "myDiv"),
       new XRaw("hello world")
     );
    
    
    public class XRaw : XText
    {
      public XRaw(string text):base(text){}
      public XRaw(XText text): base(text){}
    
      public override void WriteTo(System.Xml.XmlWriter writer)
      {
        writer.WriteRaw(this.Value);
      }
    }
    

提交回复
热议问题