# Table of Contents

# 1 General

#### 1.1 Is it possible to change names assigned to anonymous types?

By default XSD uses the name of an enclosing element or attribute to name an anonymous type. You can alter this behavior with the `--anonymous-regex` option which is described in the XSD Compiler Command Line Manual. For example, the following invocation of the compiler appends '`Type`' to the name of each anonymous type:

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

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

    xsd ... --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 object models. 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 a consistent object model, 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.