2013-08-06 28 views
0

如何設置一個xsd:元素類型爲XMLSchema(它定義了XSD文件的結構)?它甚至有可能嗎?聲明一個xml模式類型的元素

例如,我需要它列出它的根元素下的多個XSD的XML文件:

<schemas xmlns:xs=''> 
    <xs:schema...> 
    <xs:element name='...'/> 
    </xs:schema> 
    <xs:schema...> 
    </xs:schema> 
</schemas> 

該XML的模式是這樣的:

<xs:schema xmlns:xs=''> 
    <xs:element name='schemas'> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name='schema' type='xs:schema' 
      minoccurs='0' maxoccurs='unbounded'/> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

當然,還有沒有這樣的類型xs:schema。我該如何做這項工作?

回答

3

是的,這是完全有可能的。具體方法如下:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <!-- 
    Any XML schema processor does know XML schema language, 
    but it is not supposed to know an XML schema for it. 
    You need to import it! 
    --> 
    <xs:import namespace="http://www.w3.org/2001/XMLSchema" 
      schemaLocation="http://www.w3.org/2001/XMLSchema.xsd"/> 

    <xs:element name="schemas"> 
    <xs:complexType> 
     <xs:sequence> 
     <!-- 
      You don't need an 'xs:schema' type. Rather you just need 
      to reference an already existing 'xs:schema' element 
     --> 
     <xs:element minoccurs="0" maxoccurs="unbounded" ref="xs:schema"/> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 

</xs:schema> 

您可能還需要查看XML架構XSLT: http://www.w3.org/2007/schema-for-xslt20.xsd。 它們在<xsl:import-schema>元素的定義中也是這樣做的。