Specify different Use attribute of SimpleType when inherited?

This should cover W3C XML Schema, Relax NG and DTD related problems.
gss
Posts: 2
Joined: Mon Nov 14, 2011 9:16 pm

Specify different Use attribute of SimpleType when inherited?

Post by gss »

First, I am evaluating OxygenXML and so far have found it to be a very good, capable xml and xml schema development tool. Thank you!

That said, I am also relatively new to xml schemas, their syntax and capabilities for describing a particular xml syntax. So, given this example schema code:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="BaseElementType">
<xs:attribute name="Attr1" type="xs:string" use="required"/>
<xs:attribute name="Attr2" type="xs:unsignedByte" use="optional"/>
<xs:attribute name="Attr3" type="xs:unsignedShort" use="optional"/>
</xs:complexType>
<xs:element name="Element1" type="BaseElementType">
<xs:annotation>
<xs:documentation>
This element uses the base element attributes as specified, where Attr1
is a required attribute, but Attr2 and Attr3 are optional.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Element2" type="BaseElementType">
<xs:annotation>
<xs:documentation>
This element uses the base element attributes but for this element I
want Attr2 to be a required attribute.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
I am wondering how to achieve what I asked for in the annotation for Element2 in the code?

Thanks in advance for any help with this!
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Specify different Use attribute of SimpleType when inherited?

Post by george »

One possibility is to define a new type that restricts the base type making that attribute required and then use that for the second element:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="BaseElementType">
<xs:attribute name="Attr1" type="xs:string" use="required"/>
<xs:attribute name="Attr2" type="xs:unsignedByte" use="optional"/>
<xs:attribute name="Attr3" type="xs:unsignedShort" use="optional"/>
</xs:complexType>
<xs:element name="Element1" type="BaseElementType">
<xs:annotation>
<xs:documentation>
This element uses the base element attributes as specified, where Attr1
is a required attribute, but Attr2 and Attr3 are optional.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="BaseElementType2">
<xs:complexContent>
<xs:restriction base="BaseElementType">
<xs:attribute name="Attr2" type="xs:unsignedByte" use="required"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="Element2" type="BaseElementType2">
<xs:annotation>
<xs:documentation>
This element uses the base element attributes but for this element I
want Attr2 to be a required attribute.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Best Regards,
George
George Cristian Bina
gss
Posts: 2
Joined: Mon Nov 14, 2011 9:16 pm

Re: Specify different Use attribute of SimpleType when inherited?

Post by gss »

George, thanks for the very quick response. What you suggested works well. Thank you!

I may ask additional questions in other areas as I hit road blocks, so I hope your tolerance for a beginning schema developer is set high! :-)
Post Reply