Writing XML Elements

Now that the XML declaration is written, it's time to start writing some real XML data. The most important node is the XML element. Elements can be written piece by piece or all at once.

Writing an element piece by piece is necessary when the element needs to contain attributes or child nodes. The XmlTextReader provides WriteStartElement and WriteEndElement to support this functionality. Calling WriteStartElement will write the specified start tag and associate it with an optional namespace and prefix. After the start tag is written, you can then write attributes on the element. You can also write child nodes. But you can no longer write an attribute on an element after a child node has been written.

Listing 10.23 demonstrates ...

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.