I’ve read the W3C docs, read the tutorials, read various posts here, still don’t understand why the following schema definition is flagged as invalid in Visual Studio 2010 (version 10.0.4.0219.1).
Would appreciate any help that might be provided. Here is a sample schema definition that demonstrates the issue.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.tempuri.org/WhyDoesThisFail"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:why="http://www.tempuri.org/WhyDoesThisFail">
<!-- Write a valid XSD to describe the following:
<SomeField alias="SomeAlias">1234.5678</SomeField>
-->
<xs:attributeGroup name="FieldAlias">
<xs:attribute name="alias" type="xs:string" />
</xs:attributeGroup>
<xs:complexType name="DecimalWithAlias">
<xs:simpleContent>
<xs:restriction base="xs:decimal">
<xs:attributeGroup ref="why:FieldAlias" />
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
<xs:element name="SomeField" type="why:DecimalWithAlias"/>
</xs:schema>
Message displayed in Visual Studio (blue underline on xs:restriction) is:
Undefined complexType “http://www.w3.org/2001/XMLSchema:decimal” is used as a base for complex type restriction.
Others indicated that either a simpleType or complexType must be added to define the restriction from the base type — but I’m unable to do that, without receiving this same error message.
Appreciate your help.
XSD has two different kinds of inheritance – extension and restriction. This is a case of an extension. This particular example is similar to yours, extension of a simple type into a complex type by adding an attribute.