The XML Writer Programming Interface

An XML writer represents a component that provides a fast, forward-only way of outputting XML data to streams or files. More important, an XML writer guarantees—by design—that all the XML data it produces conforms to the W3C XML 1.0 and Namespace recommendations.

Suppose you have to render in XML the contents of a string array. The following code normally fits the bill:

 void CreateXmlFile(String[] theArray, string filename) {     StringBuilder sb = new StringBuilder("");     // Loop through the array and build the file     sb.Append("<array>");     foreach(string s in theArray)     {         sb.Append("<element value=\"");         sb.Append(s);         sb.Append("\"/>");     }     sb.Append("</array>"); ...

Get Applied XML Programming for Microsoft® .NET 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.