This is a quick introduction to the mapping of the W3C XML Schema constructs to the C++ programming language. This mapping represents information stored in XML instance documents as a tree-like in-memory data structure.

The following step-by-step guide is based on the hello example which can be found in the `examples/cxx/tree/hello` directory of the xsd distribution.

1. Write a Schema definition for instance documents

  Suppose you have the following instance document (`hello.xml`):

      <?xml version="1.0"?>
      <hello xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="hello.xsd">

        <greeting>Hello</greeting>

        <name>sun</name>
        <name>earth</name>
        <name>world</name>

      </hello>

  Then, the Schema definition for the above instance could look like this (`hello.xsd`):

      <?xml version="1.0"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

        <xsd:complexType name="hello_type">
          <xsd:sequence>
            <xsd:element name="greeting" type="xsd:string"/>
            <xsd:element name="name" type="xsd:string" maxOccurs="unbounded"/>
          </xsd:sequence>
        </xsd:complexType>

        <xsd:element name="hello" type="hello_type"/>

      </xsd:schema>

2. Translate your Schema to C++

      $ xsd cxx-tree hello.xsd

  Now we have `hello.hxx` and `hello.cxx`. The following listing will give you an idea about the correspondence between W3C XML Schema and C++.

3. Implement application logic

  At this point we have all the tools we need to do something useful with the information stored in instance documents (`driver.cxx`):

      #include "hello.hxx"

      int
      main (int argc, char* argv[])
      {
        auto_ptr<hello_type> h (hello (argv[1]));

        for (hello_type::name::const_iterator i (h->name ().begin ());
             i != h->name ().end ();
             ++i)
        {
          cerr << h->greeting () << ", " << *i << "!" << endl;
        }
      }

4. Compile and run

      $ g++ -o driver driver.cxx hello.cxx -lxerces-c
      $ ./driver hello.xml
      Hello, sun!
      Hello, moon!
      Hello, world!

5. Learn more

  The library example, which can be found in the `examples/cxx/tree/library` directory of the xsd distribution, shows how to

  - handle more complicated data structures
  - use the ID/IDREF cross-referencing mechanism
  - use the `xsd:enumeration` to C++ `enum` mapping
  - modify an in-memory representation
  - serialize the modified in-memory representation back to XML

  The mixed example, which can be found in the `examples/cxx/tree/mixed` directory of the xsd distribution, shows how to access underlying DOM nodes in order to handle "type-less content" such as mixed content models, `xsd:anyType`, `xsd:anySimpleType`, `xsd:any`, and `xsd:anyAttribute`.

  The polymorphism example, which can be found in the `examples/cxx/tree/polymorphism` directory of the xsd distribution, shows how to use XML Schema polymorphism features such as `xsi:type` attribute and substitution groups.

  For a comprehensive description of the C++/Tree mapping, including parsing and serialization mechanisms, refer to XML Schema C++/Tree Mapping User Manual.