[xsd-users] Attempting to access attribute xml:base.

Boris Kolpackov boris at codesynthesis.com
Wed Sep 12 04:13:11 EDT 2007


Hi Jeroen,

Jeroen N. Witmond [Bahco] <jnw at xs4all.nl> writes:

> Instead I have gotten xsd to generate all required code in
> a custom type, without making any changes to xsd itself.

This is a clever trick. I see you use sed to re-map the XML Schema
namespace to xml_schema_2 when compiling XmlNamespace.xsd in order to
avoid name clashes. You can achieve the same result by adding the
following options to the command line:

--namespace-map http://www.w3.org/2001/XMLSchema=xml_schema_2

Unfortunately, this whole approach has a number of deficiencies
and won't work for the general case, as you have described in your
other email.

The problem is that anyType is quite a special type. It is a
root of the generated type hierarchy and as such is a base
for both simple types (i.e., type with only text content)
and complex types (i.e., types with attributes and/or elements).

Because simple types can be used as attribute and list element
types, anyType includes parsing constructors for DOMAttr, etc.

On the other hand, complex types cannot be used as attribute
or list element types. Because of this restriction, XSD does
not generate those constructors (DOMAttr, etc.) for complex
types.

Now if we look at your XmlNamespace.xsd:

  <complexType name="wrapper_type">
    <complexContent>
      <extension base="anyType">
        <attribute ref="xml:base"/>
      </extension>
    </complexContent>
  </complexType>

This type is a complex type because it contains the xml:base attribute.
As a result the attribute/list constructors are not generated. But when
you try to use it as anyType, those constructors are required.

Boris




More information about the xsd-users mailing list