我如何定义不同XSD文件之间的一对多关系,为什么xs:extends在这种情况下不起作用?
在过去的几天里,我一直在开发一些xml模式文件,并学习了一个扩展SimpleType和complextype元素的特定元素 我目前使用的是visual studio 2012专业版,我目前正在测试这些文件之间的XSD文件关系(我敢说是父子关系,或一对多关系),例如(我使用的是来自Google DFA API的对象): 所有这些类都是从RichMediaAsset(基础或抽象)中“扩展”或“继承”的。我在XSD中将RichMediaAsset定义如下我如何定义不同XSD文件之间的一对多关系,为什么xs:extends在这种情况下不起作用?,xsd,visual-studio-2012,one-to-many,Xsd,Visual Studio 2012,One To Many,在过去的几天里,我一直在开发一些xml模式文件,并学习了一个扩展SimpleType和complextype元素的特定元素 我目前使用的是visual studio 2012专业版,我目前正在测试这些文件之间的XSD文件关系(我敢说是父子关系,或一对多关系),例如(我使用的是来自Google DFA API的对象): 所有这些类都是从RichMediaAsset(基础或抽象)中“扩展”或“继承”的。我在XSD中将RichMediaAsset定义如下 <?xml version="1.0"
<?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>
现在的问题是:这是2012年的一个可能的错误吗?我是否犯了错误?这只是不受支持(即使我在w3schools.com上查看了使用示例),还是有更好的方法来定义一对多关系?我发现了XSD的问题。事实上,它丢失了一个标签。在这些情况下,必须定义
xs:complexContent
或xs:simpleContent
,以便分别对只包含混合内容或元素的复杂/简单类型定义扩展或限制
这是我的解决方案,代码中的错误也消失了
<?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:complexContent>
<xs:extension base="RichMediaAssetWrapper">
<xs:sequence>
...
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
...
资料来源:
<?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>
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
<?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:complexContent>
<xs:extension base="RichMediaAssetWrapper">
<xs:sequence>
...
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>