Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 655

New Post: OptionWriteEmptyNodes break XML declaration

$
0
0

I use HtmlAgilityPack to load HTML and write back, and I set OptionWriteEmptyNodes to true so as to keep the empty node, but if set OptionWriteEmptyNodes to ture, the XML declaration in origial HTML is also modified incorrectly.

Here is my code:

            var doc = new HtmlDocument();
            doc.OptionWriteEmptyNodes = true;
            doc.LoadHtml(@"<?xml version=""1.0"" encoding=""utf-8"" ?> This is a test<br/>html");

            var postParsed = doc.DocumentNode.WriteTo();

The output is:

<?xml version="1.0" encoding="utf-8" /> This is a test<br />html

You can see that the XML declaration <?xml version="1.0" encoding="utf-8" ?> is change incorrectly to <?xml version="1.0" encoding="utf-8" />

How to avoid this issue when set OptionWriteEmptyNodes to true?


Viewing all articles
Browse latest Browse all 655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>