我有一个像这样的xsd
<xsd:complexType name="A"> <xsd:complexContent> <xsd:sequence> <xsd:element name="options"> <xsd:complexType> <xsd:sequence> <xsd:element name="Day"> ... </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="B"> <xsd:complexContent> <xsd:extension base="A"> ...What would go here... </xsd:extension> </xsd:complexContent> </xsd:complexType>
所以基本上我想要A类有一个选项序列(例如Day,Week),然后我希望B继承A,并拥有所有的A选项和额外的2或3选项,如小时,秒。
这里是我想出的模式:
<?xml version="1.0" encoding="utf-8"?> <schema id="inheritance" targetNamespace="http://test.com" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:test="http://test.com" > <element name="Time"> <complexType> <sequence> <element name="First" type="test:A" /> <element name="Second" type="test:B" /> </sequence> </complexType> </element> <complexType name="shortOptions"> <sequence> <element name="Day" /> </sequence> </complexType> <complexType name="longOptions"> <complexContent> <extension base="test:shortOptions"> <sequence> <element name="Week" /> </sequence> </extension> </complexContent> </complexType> <complexType name="A"> <sequence> <element name="options" type="test:shortOptions" /> </sequence> </complexType> <complexType name="B"> <sequence> <element name="options" type="test:longOptions" /> </sequence> </complexType> </schema>
其中似乎适合这个xml:
<?xml version="1.0" encoding="utf-8" ?> <Time xmlns="http://test.com"> <First> <options> <Day>Today</Day> </options> </First> <Second> <options> <Day>Tomorrow</Day> <Week>This Week</Week> </options> </Second> </Time>