XSD: How to declare element with concrete implementation of abstract type?
There is AppData element which contains an abstract element Document.
<xs:element name="AppData">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:Document"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Document" type="tns:TDocument" abstract="true"/>
<xs:complexType name="TDocument">
<xs:sequence>
<xs:any namespace="##any" processContents="lax"/>
</xs:sequence>
</xs:complexType>
There are also two different insta开发者_运维百科nce elements of Document:
<xs:element name="Rq3" type="tns:Y" substitutionGroup="smev:Document"/>
<xs:element name="Rq4" type="tns:Z" substitutionGroup="smev:Document"/>
<xs:complexType name="Y">
<xs:complexContent>
<xs:restriction base="smev:TDocument">
<xs:sequence>
<xs:element ref="rq3:Doc"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Z">
<xs:complexContent>
<xs:restriction base="smev:TDocument">
<xs:sequence>
<xs:element ref="rq4:Doc"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
And the challenge is to define the type of AppData element corresponding to concrete instance of Document (Rq3):
schema screenshot: http://i54.tinypic.com/ab74ls.png
How to define the type for the following xml (AppData containing Rq3):
<x:MessageData>
<x:AppData>
<rq3:Doc>...</rq3:Doc>
</x:AppData>
</x:MessageData>
Please suggest a solution.
If I understand the question correctly, you want to define an element declaration for MessageData that allows it to contain an AppData child, provided that the child of AppData must be an rq3:Doc element and not some other member of the substitution group (such as rq4:Doc). Is that correct?
This is a little tricky because when you say that rq3:Doc is substitutable for Doc, that really means it is substitutable everywhere, not just substitutable in selected places. You may be better off having a local definition of AppData-within-MessageData whose type is more restrictive than that of the global AppData element.
精彩评论