2016-01-28 42 views
1

我们正在构建企业范围的XML模式。在由不同团队构建的架构之间存在通用元素,我们希望他们都使用相同数据元素的相同名称,以便他们能够使用相同的数据字典。在XSD中共享定义的技巧?

为我们打造出的模式,但希望他们都使用例如customerfirstname的同名 应该在所有不同的模式一样,我们如何做到这一点,我们会加班元素添加到数据字典?

+1

由于模式可以包含另一个模式文件,因此您可以拥有每个团队的模式包含的公共xsd。 –

回答

0

通过使用命名空间,实现XSD中共享和非共享词汇表控制的分离。

1族(和其它基团)可以定义在他们控制的命名空间的XSD,

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:g1="http://example.com/group1" 
      xmlns:c1="http://example.com/common" 
      targetNamespace="http://example.com/group1"> 

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

    <xs:element name="Group1X"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element ref="g1:Group1Y"/> 
     <xs:element ref="c1:Common1"/> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 

    <xs:element name="Group1Y" type="xs:string"/> 

</xs:schema> 

并导入在公共的,共享控制下的命名空间的XSD:

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

    <xs:element name="Common1" type="xs:string"/> 

</xs:schema> 

这样两者都可以用在同一个XML文档中

<?xml version="1.0" encoding="UTF-8"?> 
<g1:Group1X xmlns:g1="http://example.com/group1" 
      xmlns:c1="http://example.com/common" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://example.com/group1 group1.xsd"> 
    <g1:Group1Y> 
    Vocabulary in the "http://example.com/group1" namespace is under 
    the control of group 1. 
    </g1:Group1Y> 
    <c1:Common1> 
    Vocabulary in the "http://example.com/common" namespace is under 
    common control. 
    </c1:Common1> 
</g1:Group1X> 

根据要求没有冲突。