Meta-Programming with XML Schema

This chapter discusses the functionality to read, process, and use XML schema within R. The primary goal is to be able to programmatically generate R classes and code to work with XML documents. Recall from Section 2.7 that an XML schema describes the structure, content and data types for XML documents in a particular XML vocabulary, grammar or format (e.g., PMML or KML). The information in the schema can be turned into S4 class definitions and R functions for reading and generating XML in R for that XML vocabulary. We can use these S4 classes to represent data that appear in the XML documents as R objects corresponding to the schema. This means we can both read XML into objects of these classes and also generate XML by serializing these R objects to XML. The key idea is that these classes and methods for reading and writing XML are generated programmatically. The XMLSchema package provides code that generates code for a given schema. R users do not need to interact directly with the contents of a schema, but can benefit from them to create structured R code and data.