Appendix V XML
This appendix summarizes useful XML topics and techniques.
Special Characters
The following table lists five special characters defined for use in XML files.
| Character | Code |
< | < |
> | > |
& | & |
' | ' |
" | " |
You can also include special characters inside CDATA sections. A CDATA section begins with <![CDATA[ and includes all the following text until it reaches the closing sequence ]]>. The CDATA can include carriage returns, ampersands, quotes, and other special characters.
Writing XML Data
The .NET Framework provides two main ways to write XML data: the XmlWriter class and the XML Document Object Model. The following two sections describe these approaches.
XmlWriter
The XmlWriter class provides methods for writing the pieces of an XML file. To use an XmlWriter to write XML data into a file, call the class’s Create method to create the file. Then use the other methods to write the pieces of the XML document into the file.
The following table lists the most useful XmlWriter methods.
| Method | Purpose |
Close | Closes the writer’s underlying stream. |
Create | Creates an XmlWriter associated with a file, stream, StringBuilder, or other object. |
Dispose | Frees the writer’s resources. (You can use the using statement to ensure that the writer is disposed.) |
Flush | Flushes output to the underlying stream. |
WriteAttributeString | Writes an attribute with a specified name and value. |
WriteCData | Writes CDATA. |
WriteComment | Writes a comment. |
WriteElementString | Writes an element with a specified name ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access