2017-01-24 28 views
0

在XSD文件中,如何限制要包含在由其他元素定義的值中的元素的值? 換句話說,要聲明某個值,它必須已經被其他元素實例化。XSD - 限制要包含在由其他元素定義的值中的元素的值

例如:

我有傳感器列表,

<SensorDefinitionList> 
    <SensorDefinition> 
    <Name>ROLK8900</Name> 
    <DisplayName>TRM1</DisplayName> 
    <Presence>YES</Presence> 
    <SensorId>40</SensorId> 
    <Coordinates>0,0</Coordinates> 
    </SensorDefinition> 
    <SensorDefinition> 
    <Name>JBLK7200</Name> 
    <DisplayName>JBLK</DisplayName> 
    <Presence>YES</Presence> 
    <SensorId>35</SensorId> 
    <Coordinates>0,0</Coordinates> 
    </SensorDefinition> 
    ... 
</SensorDefinitionList> 

和含有它們的分佈,例如一個元件:

<SensorDistributionList> 
    <SensorDistribution> 
    <SensorDistributionId>0</SensorDistributionId> 
    <Name>System</Name> 
    <ListOfSensor>SDF</ListOfSensor> 
    </SensorDistribution> 
    <SensorDistribution> 
    <SensorDistributionId>3</SensorDistributionId> 
    <Name>MLAT</Name> 
    <ListOfSensor>MLAT</ListOfSensor> 
    </SensorDistribution> 
    ... 
</SensorDistributionList> 

在XSD,我想向我所描述的SensorDistribution名稱是之前在SensorDefinition中定義的傳感器名稱。 如何以這種方式編寫我的XSD?

... 
<xs:element name="SensorDistributionList"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element maxOccurs="unbounded" name="SensorDistribution"> 
     <xs:complexType> 
      <xs:sequence> 
      <xs:element name="SensorDistributionId" type="xs:integer" /> 
      <xs:element name="Name" type="xs:string" /> 
      <xs:element name="ListOfSensor" type="xs:string" /> 
      </xs:sequence> 
     </xs:complexType> 
     </xs:element> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 
... 

回答

0

您可以定義的SensorDefinition名稱作爲xs:IDSensorDistribution使用它。更多 :

 <xs:element maxOccurs="unbounded" name="SensorDefinition"> 
     <xs:complexType> 
      <xs:sequence> 
      ... 
      <xs:element name="Name" type="xs:ID" /> 
      </xs:sequence> 
     </xs:complexType> 
     </xs:element> 

     <xs:element maxOccurs="unbounded" name="SensorDistribution"> 
     <xs:complexType> 
      <xs:sequence> 
      ... 
      <xs:element name="Name" type="xs:IDREF" /> 
      </xs:sequence> 
     </xs:complexType> 
     </xs:element> 

更多