Image tag not closing with HTMLAgilityPack

前端 未结 4 1951
感情败类
感情败类 2020-12-01 16:59

Using the HTMLAgilityPack to write out a new image node, it seems to remove the closing tag of an image, e.g. should be but when you check outer html, has .



        
4条回答
  •  情歌与酒
    2020-12-01 17:35

    This seems to be a bug with HtmlAgilityPack. There are many ways to reproduce this, for example:

    Debug.WriteLine(HtmlNode.CreateNode("").OuterHtml);
    

    Outputs malformed HTML. Using the suggested fixes in the other answers does nothing.

    HtmlDocument doc = new HtmlDocument();
    doc.OptionOutputAsXml = true;
    HtmlNode node = doc.CreateElement("x");
    node.InnerHtml = "";
    doc.DocumentNode.AppendChild(node);
    Debug.WriteLine(doc.DocumentNode.OuterHtml);
    

    Produces malformed XML / XHTML like

    I have created a issue in CodePlex for this.

提交回复
热议问题