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 ...
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