创建多个XSD库

时间:2011-07-15 15:10:35

标签: xsd

我有可能拥有相当多的小型XSD,其中包含大型项目的各种类型。 (组分)

我还有大量的XSD需要大量的这些个人XSD。 (屏幕)

我知道我可以将每个“组件”导入每个“屏幕”XSD。但是每个人都要做很多工作。

我希望能做的是将这些“组件”中的每一个导入到单个XSD(ComponentLibrary)中,然后将这个“ComponentLibrary”导入到每个“Screen”XSD中。

我编写了我认为可能已经需要的代码,但它似乎并不想工作。我得到的错误是未申报的。

TF.xsd:

<xs:schema targetNamespace="http://namespace.com/TF"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">

    <xs:complexType name="TFType">
        <xs:attribute name="size" type="xs:decimal" />
        <xs:attribute name="colour" type="xs:decimal" />
    </xs:complexType>
</xs:schema>

ComponentsLibrary.xsd:

<xs:schema targetNamespace="http://namespace.com/ComponentsLibrary"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tf="http://namespace.com/TF"
    elementFormDefault="qualified">

    <xs:import schemaLocation="TF.xsd" namespace="http://namespace.com/TF"/>
    <xs:element name="TF" type="tf:TFType" />
</xs:schema>

Screen1.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:cl="http://namespace.com/ComponentsLibrary" 
    elementFormDefault="qualified">

    <xs:import schemaLocation="ComponentsLibrary.xsd" namespace="http://namespace.com/ComponentsLibrary" />

    <xs:element name="tfTitle" type="cl:TF" />
</xs:schema>

我遇到错误

Screen1.xsd (8:3) Error Type 'http://namespace.com/Components:TF' is not declared.

1 个答案:

答案 0 :(得分:2)

您的组件库架构声明了元素 TF,而不是类型 TF,因此Screen1.xsd中出现错误。

如果您真的想在ComponentLibrary中使用TF类型,那么您可以使用chameleon schema approach

  • TF.xsd应该没有命名空间
  • ComponentLibrary应包含(不导入)TF.xsd
  • TF.xsd中的所有类型现在都可以在ComponentLibrary命名空间下使用