Reputation: 3
Thank you! @Yitzhak Khabinsky I copy a small example as below:
In XSD file defined as blow:
<?xml version="1.0"?>
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
vc:minVersion="1.1"
>
<xs:element name="CalculationProcess">
<xs:complexType>
<xs:sequence>
<xs:element name="CalculationStep" type="CalculationStepType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:unique name="UniqueId">
<xs:selector xpath="CalculationStep"/>
<xs:field xpath="@Id" />
</xs:unique>
</xs:element>
<xs:complexType name="CalculationStepType">
<xs:sequence>
<xs:element name="Parameter">
<xs:complexType>
<xs:all>
<xs:element name="AdditionalData" type="AddData" minOccurs="0">
<xs:alternative test="@Type = 'Woodham'" type="AddDataWoodham"/>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Id" use="required" inheritable="true">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="Name" type="xs:string" use="required" inheritable="true" />
<xs:attribute name="Type" type="TCalculationStepType" use="required" />
<xs:attribute name="InputCount" type="xs:integer" use="required" />
<xs:attribute name="OutputCount" type="xs:integer" use="required" />
<!-- StreamId must > 0 -->
<xs:attribute name="StreamId" use="required" >
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<!-- CalculationStep@Type must match one of the enumerations -->
<xs:simpleType name="TCalculationStepType">
<xs:restriction base="xs:string">
<xs:enumeration value="Woodham" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="AddData" abstract="true"/>
<xs:complexType name="AddDataWoodham">
<xs:complexContent>
<xs:extension base="AddData">
<!--PhotostereoWoodham-->
<xs:all>
<xs:element name="FilePath" type="xs:string" minOccurs="1" />
<xs:element name="ScaleFactorP" type="xs:decimal" minOccurs="1" />
<xs:element name="ScaleFactorQ" type="xs:decimal" minOccurs="1" />
<xs:element name="CalculationMethod" type="xs:integer" minOccurs="1" />
<xs:element name="SlantLookupSize" type="xs:integer" minOccurs="1" />
<xs:element name="TiltLookupSize" type="xs:integer" minOccurs="1" />
</xs:all>
</xs:extension >
</xs:complexContent>
</xs:complexType>
</xs:schema>
XML file:
<?xml version='1.0'?>
<CalculationProcess xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ObjCalcConfig.xsd">
<CalculationStep Id='0' Name='Woodham' Type='Woodham' InputCount='4' OutputCount='3' StreamId='1'>
<Parameter>
<AdditionalData>
<FilePath>files\matrix.xml</FilePath>
<ScaleFactorP>1.5</ScaleFactorP>
<ScaleFactorQ>1.5</ScaleFactorQ>
<CalculationMethod>2</CalculationMethod>
<SlantLookupSize>25</SlantLookupSize>
<TiltLookupSize>72</TiltLookupSize>
</AdditionalData>
</Parameter>
</CalculationStep>
</CalculationProcess>
But I get a error: enter image description here
I don't know where is the problem, could someone please help me to resolve this error. THANK YOU!!!
I tried do abstract="false", that doesn't work because the base element is empty...
Upvotes: 0
Views: 109
Reputation: 163262
I'm not sure what you are trying to achieve here.
Your type alternative rules are saying that if @Type
is "Woodham", then the element should have type AddDataWoodham
; if the Type
attribute is absent or has any other value (which is the case for your example), then the element should have type AddData
; but an element cannot have type AddData
because the type is abstract. So that's clearly an error.
Your instance seems to conform to type AddDataWoodham
, but it isn't being validated against that type, because it doesn't have a Type
attribute with value Woodham
.
Upvotes: 0