在过去的几天里,我一直在开发一些 xml 模式文件,并了解了一个特定的元素来扩展 simpletypes 和 complextype 元素。
我目前正在使用visual studio 2012专业版,并且我目前正在测试这些文件之间的XSD文件关系(我敢说父子关系,或一对多关系),例如(我正在使用来自Google DFA API的对象) :
RichMediaAsset
∟ RichMediaExpandingHtmlAsset
∟ RichMediaExpandingHtmlAsset
∟ RichMediaFloatingHtmlAsset
...
所有这些类都从 RichMediaAsset(它是基础或抽象)“扩展”或“继承”。我在 XSD 中将 RichMediaAsset 定义为以下内容
<?xml version="1.0" standalone="yes"?>
<xs:schema id="RedirectCreativeBase" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<!-- simpleTypes=primitive -->
<!-- extBooleanMethodPrefix=is -->
<xs:complexType name="RichMediaAssetWrapper" abstract="true">
<xs:sequence>
<xs:element name="fileName" type="xs:string" minOccurs="0" />
<xs:element name="fileSize" type="xs:int" minOccurs="0" />
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="parentAssetId" type="xs:long" minOccurs="0" />
<xs:element name="type" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
我定义了第二个文件 RichMediaExpandingHtmlAsset 如下:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="RichMediaExpandingHtmlAssetWrapper" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="./RichMediaAsset.xsd"/>
<xs:complexType name="RichMediaExpandingHtmlAssetWrapper" abstract="false" >
<xs:extension base="RichMediaAssetWrapper"> <!-- Not happy here -->
<xs:sequence>
<!-- content to be included,extending RichMediaAsset's complex type called RichMediaAssetWrapper -->
</xs:sequence>
</xs:extension>
</xs:complexType>
</xs:schema>
我提到的VS2012不满意的部分定义如下:
Warning 1 The 'http://www.w3.org/2001/XMLSchema:extension' element is not supported in this context. C:\eclipse\Workspace\aem_adservices_google_dfa\aem.adservices.google.dfa\xsd\Creative\RichMediaExpandingHtmlAsset.xsd 5 6 Miscellaneous Files
Warning 2 The element 'complexType' in namespace 'http://www.w3.org/2001/XMLSchema' has invalid child element 'extension' in namespace 'http://www.w3.org/2001/XMLSchema'. List of possible elements expected: 'annotation, simpleContent, complexContent, group, all, choice, sequence, attribute, attributeGroup, anyAttribute' in namespace 'http://www.w3.org/2001/XMLSchema'. C:\eclipse\Workspace\aem_adservices_google_dfa\aem.adservices.google.dfa\xsd\Creative\RichMediaExpandingHtmlAsset.xsd 5 6 Miscellaneous Files
现在的问题是:这可能是 2012 年的错误吗,我是否犯了错误,这是否根本不受支持(即使我检查了 w3schools.com 上的用法示例),还是有更好的方法让我定义一对多关系?