Chapter 6. Processing XML

Extensible Markup Language (XML) was introduced to the world with much hullabaloo by the World Wide Web Consortium (W3C) in 1996. Building on the popularity of its ancestor, SGML, and its sibling, HTML, XML has continued to provide employment for programmers, authors, and pundits ever since.

When the .NET Framework was introduced in 2000, XML formed an important building block in the Common Language Runtime. By supporting the core XML standards-Document Object Model, XPath, XSLT, and W3C XML Schema-as well as XML serialization, .NET provides almost everything a Mono hacker needs to hack XML. And what .NET itself does not provide, the Mono team and other open source contributors have provided with a managed implementation of Relax NG.

In this age, XML should be part of every programmer’s repertoire. This chapter introduces you to Mono’s XML support.

Read and Write XML

The simplest thing you can do with XML is to read and write it. The System.Xml namespace contains the XmlReader and XmlWriter classes, as well as a number of supporting classes, expressly for that purpose. This lab shows you the basics.

Note

For those times when memory is limited and you just need to grab a chunk of data.

How do I do that?

Example 6-1 shows a program that writes XML to standard output.

Example 6-1. 01-basic/WriteXml.cs
// 06-xml/01-basic using System; using System.Collections; using System.IO; using System.Xml; public class WriteXml { private const string RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; ...

Get Mono: A Developer's Notebook 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.