Connecting Tech Pros Worldwide Forums | Help | Site Map

Inheritance in XSD?

Bill Cohagan
Guest
 
Posts: n/a
#1: Nov 12 '05
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/#no...e-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



Dare Obasanjo [MSFT]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Inheritance in XSD?


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.

"Bill Cohagan" <bill@teraXNOSPAMXquest.com> wrote in message
news:%2328KPagREHA.644@tk2msftngp13.phx.gbl...[color=blue]
> I'd like to define a schema that allows, for example, a "table" element[/color]
that[color=blue]
> takes on one of two forms distinguished by what attributes are present.[/color]
For[color=blue]
> 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[/color]
in[color=blue]
> XML Schema itself. It can have a type attribute or a ref attribute, but[/color]
not[color=blue]
> 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[/color]
could[color=blue]
> define both attributes in the base type, then derive by restriction,[/color]
setting[color=blue]
> 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[/color]
get[color=blue]
> 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[/color]
tried[color=blue]
> 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/#no...e-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
>
>[/color]


Dare Obasanjo [MSFT]
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Inheritance in XSD?


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.

"Bill Cohagan" <bill@teraXNOSPAMXquest.com> wrote in message
news:%2328KPagREHA.644@tk2msftngp13.phx.gbl...[color=blue]
> I'd like to define a schema that allows, for example, a "table" element[/color]
that[color=blue]
> takes on one of two forms distinguished by what attributes are present.[/color]
For[color=blue]
> 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[/color]
in[color=blue]
> XML Schema itself. It can have a type attribute or a ref attribute, but[/color]
not[color=blue]
> 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[/color]
could[color=blue]
> define both attributes in the base type, then derive by restriction,[/color]
setting[color=blue]
> 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[/color]
get[color=blue]
> 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[/color]
tried[color=blue]
> 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/#no...e-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
>
>[/color]


Kevin Yu [MSFT]
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Inheritance in XSD?


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."

Kevin Yu [MSFT]
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Inheritance in XSD?


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."

Bill Cohagan
Guest
 
Posts: n/a
#6: Nov 12 '05

re: Inheritance in XSD?


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
"Dare Obasanjo [MSFT]" <dareo@online.microsoft.com> wrote in message
news:%23gsnN6sREHA.3348@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
rights.[color=blue]
>
> "Bill Cohagan" <bill@teraXNOSPAMXquest.com> wrote in message
> news:%2328KPagREHA.644@tk2msftngp13.phx.gbl...[color=green]
> > I'd like to define a schema that allows, for example, a "table" element[/color]
> that[color=green]
> > takes on one of two forms distinguished by what attributes are present.[/color]
> For[color=green]
> > instance,
> >
> > <table foo="3"/>
> > <table bar="5"/>
> >
> > Note that I want to exclude <table foo="3" bar = "5"/>; i.e., using[/color][/color]
*both*[color=blue][color=green]
> > attributes should fail to validate.
> >
> > A familiar example of this sort of thing is the element named[/color][/color]
xsd:element[color=blue]
> in[color=green]
> > XML Schema itself. It can have a type attribute or a ref attribute, but[/color]
> not[color=green]
> > both. It would appear there are several ways to do this sort of thing.[/color][/color]
One[color=blue][color=green]
> > 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[/color]
> could[color=green]
> > define both attributes in the base type, then derive by restriction,[/color]
> setting[color=green]
> > the use of the "excluded" attribute to prohibited. Both approaches seem[/color][/color]
to[color=blue][color=green]
> > 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[/color]
> get[color=green]
> > an error complaining that the schema is not deterministic due to[/color][/color]
multiple[color=blue][color=green]
> > elements named "table". Now I've read about the xsi:type attribute and[/color]
> tried[color=green]
> > 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/#no...e-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[/color][/color]
within[color=blue][color=green]
> > the VS2003 IDE and the .Net XML implementation?
> >
> > Thanks in advance for any suggestions or pointers.
> >
> > Bill
> >
> >[/color]
>
>[/color]


Bill Cohagan
Guest
 
Posts: n/a
#7: Nov 12 '05

re: Inheritance in XSD?


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
"Dare Obasanjo [MSFT]" <dareo@online.microsoft.com> wrote in message
news:%23gsnN6sREHA.3348@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
rights.[color=blue]
>
> "Bill Cohagan" <bill@teraXNOSPAMXquest.com> wrote in message
> news:%2328KPagREHA.644@tk2msftngp13.phx.gbl...[color=green]
> > I'd like to define a schema that allows, for example, a "table" element[/color]
> that[color=green]
> > takes on one of two forms distinguished by what attributes are present.[/color]
> For[color=green]
> > instance,
> >
> > <table foo="3"/>
> > <table bar="5"/>
> >
> > Note that I want to exclude <table foo="3" bar = "5"/>; i.e., using[/color][/color]
*both*[color=blue][color=green]
> > attributes should fail to validate.
> >
> > A familiar example of this sort of thing is the element named[/color][/color]
xsd:element[color=blue]
> in[color=green]
> > XML Schema itself. It can have a type attribute or a ref attribute, but[/color]
> not[color=green]
> > both. It would appear there are several ways to do this sort of thing.[/color][/color]
One[color=blue][color=green]
> > 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[/color]
> could[color=green]
> > define both attributes in the base type, then derive by restriction,[/color]
> setting[color=green]
> > the use of the "excluded" attribute to prohibited. Both approaches seem[/color][/color]
to[color=blue][color=green]
> > 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[/color]
> get[color=green]
> > an error complaining that the schema is not deterministic due to[/color][/color]
multiple[color=blue][color=green]
> > elements named "table". Now I've read about the xsi:type attribute and[/color]
> tried[color=green]
> > 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/#no...e-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[/color][/color]
within[color=blue][color=green]
> > the VS2003 IDE and the .Net XML implementation?
> >
> > Thanks in advance for any suggestions or pointers.
> >
> > Bill
> >
> >[/color]
>
>[/color]


Closed Thread