Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 09:39 AM
Brett Gerhardi
Guest
 
Posts: n/a
Default Why isn't fixed considered a restriction?

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


  #2  
Old July 20th, 2005, 09:39 AM
Priscilla Walmsley
Guest
 
Posts: n/a
Default Re: Why isn't fixed considered a restriction?

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.

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
  #3  
Old July 20th, 2005, 09:39 AM
Stan Kitsis [MSFT]
Guest
 
Posts: n/a
Default Re: Why isn't fixed considered a restriction?

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.

"Brett Gerhardi" <brett.gerhardi@nildram.net> wrote in message
news:lMCdnQin56Kc_hbfRVnysw@pipex.net...[color=blue]
> 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
>[/color]


  #4  
Old July 20th, 2005, 09:39 AM
Brett Gerhardi
Guest
 
Posts: n/a
Default Re: Why isn't fixed considered a restriction?

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

"Stan Kitsis [MSFT]" <skits@microsoft.com> wrote in message
news:428bd5ef$1@news.microsoft.com...[color=blue]
> 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.
>
> "Brett Gerhardi" <brett.gerhardi@nildram.net> wrote in message
> news:lMCdnQin56Kc_hbfRVnysw@pipex.net...[color=green]
>> 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
>>[/color]
>
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles