O'Reilly logo

Mono: A Developer's Notebook by Edd Wilder-James, Niel M. Bornstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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#"; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required