all groups > dotnet xml > may 2004 >
You're in the

dotnet xml

group:

Inheritance in XSD?


Inheritance in XSD? Bill Cohagan
5/30/2004 12:25:43 AM
dotnet xml:
I'd like to define a schema that allows, for example, a "table" element that
takes on one of two forms distinguished by what attributes are present. For
instance,

<table foo="3"/>
<table bar="5"/>

Note that I want to exclude <table foo="3" bar = "5"/>; i.e., using *both*
attributes should fail to validate.

A familiar example of this sort of thing is the element named xsd:element in
XML Schema itself. It can have a type attribute or a ref attribute, but not
both. It would appear there are several ways to do this sort of thing. One
approach is to define an abstract tableType, then define derived types
fooTableType and barTableType. We could use extension in which case the
derived types would provide the associated attribute. Alternatively we could
define both attributes in the base type, then derive by restriction, setting
the use of the "excluded" attribute to prohibited. Both approaches seem to
work; i.e., the created XSD seems to past muster in the VS2003 IDE.

The problem is that when I attempt to validate an XML against this XSD I get
an error complaining that the schema is not deterministic due to multiple
elements named "table". Now I've read about the xsi:type attribute and tried
adding that to see if it eliminated the ambiguity, but no joy.

I found the schema for XML Schema at
http://www.w3.org/TR/xmlschema-1/#normative-schemaSchema and it uses
derivation by restriction to express this sort of thing. Apparently
Microsofts XML implementation however doesn't support this sort of
derivation.

Have I missed something fundamental or is this simply not possible within
the VS2003 IDE and the .Net XML implementation?

Thanks in advance for any suggestions or pointers.

Bill

Re: Inheritance in XSD? Dare Obasanjo [MSFT]
5/30/2004 10:17:24 PM
The .NET Framework's XML Schema supports all aspects of XSD including
derivation by restriction. There are probably errors in your schema.

What you want to do is generally not possible with W3C XML Schema. You
cannot create a "choice of attributes". You can define an abstract
tableType, then define derived types fooTableType and barTableType but in
addition should specify that the type of table is tableType in the schema
then each instance declares whether it is a fooTableType or a barTableType
using an xsi:type attribute.

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

[quoted text, click to view]

Re: Inheritance in XSD? v-kevy NO[at]SPAM online.microsoft.com
6/2/2004 3:20:26 AM
Hi Bill,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Re: Inheritance in XSD? Bill Cohagan
6/2/2004 11:30:32 AM
Dare
Thanks for the response. I will attempt to construct a "simple example"
of this that illustrates the error I'm seeing. Of course in doing so
perhaps I'll find the error if it is indeed mine!

Bill
[quoted text, click to view]

AddThis Social Bookmark Button