Writing Other Nodes

In most cases your XML will consist of only elements and attributes, but there are situations where you may need to add comments, CDATA, or other uncommon nodes to your XML document.

Writing Comments

Let's first look at writing comments. Comments can appear anywhere in the document after the prolog (everything before the root element) and even in the epilog (everything after the root element). Although the W3C XML specification states that a comment may appear anywhere in the document, even before the prolog, this is not true for documents created by the XmlTextWriter. Attempting to write a comment before writing an XML declaration will result in an InvalidOperationException. Listing 10.33 demonstrates how to add a comment ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.