# Table of Contents

# 1 General

#### 1.1 Is it possible to change names of anonymous types when automatically naming them using the --morph-anonymous option?

By default xsd uses the name of an element/attribute to name an anonymous type when anonymous morphing is requested. As a result, corresponding C++ classes and parsing/serialization functions share the same names. C++ requires you to disambiguate such names with the `class` specifier when you refer to a type instead of a function, for example:

    class object
    {
      ...
    };

    auto_ptr<class object>
    object (const string& uri);

    void
    f ()
    {
      object o1;           // error, 'object' is a function
      class object obj;    // ok, 'class object' is a type

      object ("test.xml"); // ok, 'object' is a function
    }

Instead of using the `class` specifier in your code, you can change names of anonymous types with the `--anonymous-regex` option which is described in the xsd man pages. The following invocation of the compiler appends '`Type`' to the name of each anonymous type:

    $ xsd ... --morph-anonymous --anonymous-regex '%.* .* (.+/)*(.+)%$2Type%' ...

Alternatively, you may want to make names of anonymous types start with capital letters:

    xsd ... --morph-anonymous --anonymous-regex '%.* .* (.+/)*(.+)%\u$2%' ...

# 2 Validation and Parsing

#### 2.1 Why do I get "error: Unknown element 'some-root-element'" when I try to parse a valid instance document?

This usually means that the parser could not find a schema to validate your instance document against. Since by default validation of instance documents is turned on this results in an error.

To rectify this you can either disable validation (see Question 2.2), specify the schema location in your instance document (using `xsi::schemaLocation` or `xsi::noNamespaceSchemaLocation` attributes), or specify the schema location programmatically using `xml_schema::properties` type (see Question 2.4).

#### 2.2 How to disable validation of instance documents?

By default validation of instance documents is turned on. To disable validation you will need to pass `xml_schema::flags::dont_validate` flag to one of the parsing functions, e.g.,

    auto_ptr<hello_type> h (hello (argv[1], xml_schema::flags::dont_validate));

#### 2.3 What happens if validation is disabled and an instance document is not valid?

Parsers generated by xsd do not assume instance documents are valid. They include a number of checks that prevent construction of inconsistent in-memory representations. This, however, does not mean that an instance document that was successfully parsed by the xsd-generated parsers is valid per the corresponding schema.

If an instance document is not "valid enough" for the generated parsers to construct consistent in-memory representation, one of the exceptions defined in `xml_schema` namespace is thrown.

#### 2.4 How to specify locations of schemas other than in an instance document?

You can use `xml_schema::properties` type to specify locations of schemas to be used instead of those specified with the `xsi::schemaLocation` and `xsi::noNamespaceSchemaLocation` attributes in instance documents. The following code snippet instructs the parsing function to use local schemas for validation:

    int
    main (int argc, char* argv[])
    {
      xml_schema::properties props;

      char cwd[1024];
      if (getcwd (cwd, 1024) == 0)
      {
        cerr << "cwd is longer than 1024 bytes" << endl;
        return 1;
      }

      props.schema_location (
        "http://codesynthesis.com/xmlns/foo",   // namespace
        "file://" + string (cwd) + "/foo.xsd");

      props.no_namespace_schema_location (
        "file://" + string (cwd) + "/bar.xsd");

      auto_ptr<hello_type> h (hello (argv[1], 0, props));
    }

Note that all locations are relative to an instance document unless they are full URIs. For example, if you want to use a local file, then you will need to use `file:///absolute/path/to/your/schema`, as in the code snippet above.