When using DatatypeDocumentFactory, I was surprised to find that named
simple type definitions are only considered valid if nested.  As far as I
can tell there's no reference to this in the documentation.  Have I
overlooked something and, if not, are there any plans to address this
restriction?

// When doing this:
setDocumentFactory(DatatypeDocumentFactory.getInstance());

Dom4J's SchemaParser considers this to be valid:

<!---------------------------------------------->
<xs:complexType name="NamedAttributeTesterType">
  <xs:sequence>
    <xs:element name="foo" type="xs:string" minOccurs="0"/>
  </xs:sequence>
  <xs:attribute name="kind" use="required">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="element"/>
        <xs:enumeration value="list"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
</xs:complexType>
<!---------------------------------------------->

But not this:

<!---------------------------------------------->
<xs:simpleType name="NamedAttributeType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="element"/>
    <xs:enumeration value="list"/>
  </xs:restriction>
</xs:simpleType>
<xs:complexType name="NamedAttributeTesterType">
  <xs:sequence>
    <xs:element name="foo" type="xs:string" minOccurs="0"/>
  </xs:sequence>
  <xs:attribute name="kind" type="NamedAttributeType" use="required"/>
</xs:complexType>
<!---------------------------------------------->

While I'm not crazy about the restriction, I can do something about it in my
own schemas.   Unfortunately it creates a problem when I'm attemting to
reference named types declared in other schemas.  For example:

<!---------------------------------------------->
<xs:import namespace="http://www.w3.org/XML/1998/namespace";
schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
<xs:complexType name="ReferencedAttributeTesterType">
  <xs:sequence>
    <xs:element name="foo" type="xs:string" minOccurs="0"/>
  </xs:sequence>
  <xs:attribute ref="xml:base"/>
</xs:complexType>
<!---------------------------------------------->

// Failure occurs here.  Comments mine
protected XSDatatype dataTypeForXsdAttribute( Element xsdAttribute ) {
  String type = xsdAttribute.attributeValue( "type" );
  XSDatatype dataType = null;
  // named type returns NamedAttributeTesterType and
  // then never checks simpleType
  if ( type != null ) {
    dataType = getTypeByName( type );
  }
  else {
    // only alternative is to next the type definition
    // then it works.
    Element xsdSimpleType = xsdAttribute.element( XSD_SIMPLETYPE );
    if ( xsdSimpleType == null ) {
      String name = xsdAttribute.attributeValue( "name" );
        throw new InvalidSchemaException(
        "The attribute: " + name + " has no type attribute and does not
contain a <simpleType/> element"
        );
    }
    dataType = loadXSDatatypeFromSimpleType( xsdSimpleType );
  }
  return dataType;
  }




-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to