基本上我有我的XML版本1.0,我有一个复杂的元素,有以下示例:
var time = new ol.layer.Group({ ....... });
let intervalHandle = null;
let activeLayerIndex = -1;
function startAnimation() {
// check if interval is already running
if (!intervalHandle) {
activeLayerIndex = 0;
// make sure all layers of the group are hidden
time.getLayers().forEach(layer => layer.setVisible(false));
intervalHandle = setInterval(function() {
const allLayers = time.getLayers();
if (activeLayerIndex >= allLayers.getLength()) {
// we reached the end, stop animating
stopAnimation();
}
allLayers.item(activeLayerIndex).setVisible(true);
if (activeLayerIndex > 0) {
// hide the previous layer
allLayers.item(activeLayerIndex -1).setVisible(false);
}
activeLayerIndex += 1;
}, 500 /* milliseconds */);
}
}
function stopAnimation() {
if(intervalHandle) {
clearInterval(intervalHandle);
intervalHandle = null;
}
}
我在XML Schema中定义了以下内容:
<tile>
<position>5</position>
<type>floor</type>
<towerPlacement>true</towerPlacement>
</tile>
有没有办法让我的<xs:element name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="road"/>
<xs:enumeration value="floor"/>
<xs:enumeration value="startPos"/>
<xs:enumeration value="endPos"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
成为towerPlacement
?
type = floor
答案 0 :(得分:1)
您的约束无法在XSD 1.0中表示。
您的约束可以在XSD 1.1中表达,使用断言声明towerPlacement
true
type = 'floor'
只有<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
vc:minVersion="1.1">
<xs:element name="tile">
<xs:complexType>
<xs:sequence>
<xs:element name="position" type="xs:integer"/>
<xs:element name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="road"/>
<xs:enumeration value="floor"/>
<xs:enumeration value="startPos"/>
<xs:enumeration value="endPos"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="towerPlacement" type="xs:string"/>
</xs:sequence>
<xs:assert test="(type='floor' and towerPlacement='true')
or towerPlacement!='true'"/>
</xs:complexType>
</xs:element>
</xs:schema>
:
{{1}}