The XML libraries and tools

Architecture of libxml2

the architecture of libxml

Big improvements

Deployment

Very diverse use cases:

The reader interface

import libxml2

reader = libxml2.newTextReaderFilename("ex.xml")
ret = reader.Read()
while ret == 1:
    print reader.Name()
    ret = reader.Read()

Relax-NG: the specification

More extensive validation than DTDs

Counter proposal to W3C XML Schemas

Basic example

Consider some simple XML:

<addressBook>
  <card>
    <name>John Smith</name>
    <email>js@example.com</email>
  </card>
  <card>
    <name>Fred Bloggs</name>
    <email>fb@example.net</email>
  </card>
</addressBook>

Basic DTD

The DTD for it:

<!DOCTYPE addressBook [
<!ELEMENT addressBook (card*)>
<!ELEMENT card (name, email)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT email (#PCDATA)>
]>

Basic Relax-NG schema

The Relax-NG schema for it:

<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
  <zeroOrMore>
    <element name="card">
      <element name="name">
        <text/>
      </element>
      <element name="email">
        <text/>
      </element>
    </element>
  </zeroOrMore>
</element>

Using attributes

If using attributes:

<element name="card">
  <attribute name="name">
    <text/>
  </attribute>
  <attribute name="email">
    <text/>
  </attribute>
</element>

Unified model

Relax-NG has an unified model for attributes and elements.

Using attributes or elements:

<element name="card">
  <choice>
    <element name="name">
      <text/>
    </element>
    <attribute name="name">
      <text/>
    </attribute>
  </choice>
  <choice>
    <element name="email">
      <text/>
    </element>
    <attribute name="email">
      <text/>
    </attribute>
  </choice>
</element>

Type checkig

Relax-NG allows to type-check textual content

Reuse of the W3C XML Schemas Datatype library picture of the W3C Schemas data type hierarchy

Block reuse

Modular structure using includes

Use the define and ref to reuse blocks

<element name="card">
  <ref name="cardContent"/>
</element>
...
<define name="cardContent">
  <element name="name">
    <text/>
  </element>
  <element name="email">
    <text/>
  </element>
</define>

Roadmap

Questions and Answers