« XmlTextWriter, Console.Out | Main | Window Forms, Control Layout, Docking Padding »

XML, Embedding HTML in XML

The comment syntax <!-- this is a comment --> generates an error if the comment contains “--“. Seems a bit stupid to complain about an invalid comment terminator when it isn’t intended to be a comment terminator. What gives? Do comments need to be escaped in some way?

 

SelectNodes returns a Count == 0 XMLNodeList if the xpath query matches nothing.

 

Can’t have “]]>” inside a CDATA block.

 

Encoding HTML for placement within an XML file:

XmlElement htmlNode = xqargResult.OwnerDocument.CreateElement("ds:html", nsmgr.LookupNamespace("ds"));

xqargResult.AppendChild(htmlNode);

htmlNode.InnerText = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(html));

 

Decoding the XML file to recover embedded HTML:
string html = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(result.SelectSingleNode(@"ds:html", nsmgr).InnerText));

 

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)