Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Chapter 4. XML Writers

Creating XML documents in a programmatic way has never been a particularly complicated issue. You simply concatenate a few strings into a buffer and then flush the buffer to a storage medium when you have finished. The process is quick, easy, and straightforward—could you ask for more? Well, actually, you should!

XML documents are text-based files, but they also contain a lot of markup text, and as you know, dealing with markup text can at times be boring or even annoying. More than just being a bother, you might find that supplying the necessary quotation marks and angle brackets can make your code more error-prone. Creating XML documents programmatically by simply putting one string of text after another is effective as long as you can absolutely guarantee that subtle errors will never sneak into the code mainstream, which is not much different from certifying that all of your manually created code is 100 percent bug-free.

The Microsoft .NET Framework provides a more productive, and even elegant, approach to writing XML code. Based on ad hoc tools, this approach simply applies the same pattern that has been the key to XML’s rapid adoption—focus on the data and ignore the rest. Enter XML writers.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint