在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 :(得分:0)
您可以将SensorDefinition
的名称定义为xs:ID
,并在SensorDistribution
中使用。
<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>
更多: 更多: