June 24, 2018
Hot Topics:

Writing XML Files Using the XmlTextWriter Class

  • May 6, 2005
  • By Tom Archer
  • Send Email »
  • More Articles »

Close the File and Perform Cleanup

Once you've finished writing the XML data, close the document. This is typically done with the following calls:


Taking the methods outlined in the previous section, the following bit of C++ calls various XmlTextWriter methods to generate a simple XML file:
XmlTextWriter* writer = new XmlTextWriter(S"test.xml", Encoding::ASCII);


    writer->WriteElementString(S"Author", S"Tom Archer");

      writer->WriteAttributeString(S"lang", S"EN");
      writer->WriteString(S"Writing XML Files using the XmlTextWriterClass");

      writer->WriteCData(S"http:\\\\www.test url&var=value");


This C++ code will generate the XML shown in Figure 1.

Figure 1. XML Generated By Example C++
Click here for a larger image.

Looking Ahead

This first installment of the series on using the .NET XML classes demonstrated how easy it is to generate a valid XML file with Managed C++ and the XmlTextWriter class. The next article proceeds to the next logical step: using the XmlTextReader class.

About the Author

Tom Archer owns his own training company, Archer Consulting Group, which specializes in educating and mentoring .NET programmers and providing project management consulting. If you would like to find out how the Archer Consulting Group can help you reduce development costs, get your software to market faster, and increase product revenue, contact Tom through his Web site.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date