[Solved] How can I add closed tag in xml document?


Document containing unclosed tag is not XML at all. As others suggested in comments, ideally the effort to fix this problem is done by the party that generate the document.

Regarding the original question, detecting unclosed tag in general isn’t a trivial task. I would suggest to try HtmlAgilityPack (HAP). It has built in functionality to automatically close unclosed tags (closing tag added immediately after the opening tag).

example using HAP :

using HtmlAgilityPack;

......

var xml = @"<?xml version=""1.0""?>
<rows xmlns:fo=""http://www.w3.org/1999/XSL/Format"">
<row StateID=""AK"">";
var doc = new HtmlDocument();
doc.LoadHtml(xml);
Console.WriteLine(doc.DocumentNode.OuterHtml);

output :

<?xml version="1.0"?>
<rows xmlns:fo="http://www.w3.org/1999/XSL/Format">
<row stateid="AK"></row></rows>

1

solved How can I add closed tag in xml document?