Why isn't fixed considered a restriction?

B

Brett Gerhardi

Hi all, can anyone explain why the following isn't valid?

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:complexType name="ct1">
<xsd:attribute name="a1" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="ct2">
<xsd:complexContent>
<xsd:restriction base="ct1">
<xsd:attribute name="a1" fixed="bob"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>

I would expect that adding a fixed value to the attribute would be
considered further restriction but this isn't what I want. I want to ensure
any extension of this type always has a value (and in some cases that value
will be fixed). How should I be doing this?

Thanks for any suggestions
-=- Brett
 
P

Priscilla Walmsley

Hi Brett,

It's not valid because you are not specifying a type for the attribute
in ct2. When you don't specify a type, it means that anything is
allowed, which is not more restrictive.

So, if you use:

<xsd:attribute name="a1" type="xs:string" fixed="bob"/>

you should be fine.
 
S

Stan Kitsis [MSFT]

Brett,

There are two problems with your derived type (ct2). First, you didn't
specify the type of the attribute. Second, you omitted use="required",
whcih makes the attribute optional.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:complexType name="ct1">
<xsd:attribute name="a1" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="ct2">
<xsd:complexContent>
<xsd:restriction base="ct1">
<xsd:attribute name="a1" use="required" type="xsd:string"
fixed="bob"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>

Any new type derived by extension from ct1 will have a1 attribute. You
cannot remove or modify attributes when deriving by extension. If you want
to ensure that any restriction of ct1 has a1 attribute, then specifying
use="required" (as you've done) is enough.

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Brett Gerhardi

Thank you both very much, I had presumed that it was inheriting those values
with the way that xmlspy shows it. I remember that restriction needs to be
specifically re-defined.

Strange though that xmlspy does provide duplicate the necessary child types
when changing to restriction, but it doesn't for attributes. I'll remember
that one

Thanks again! :)
-=- Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top