XML架构验证-验证相同参数名称上的属性值
我想执行xml模式验证。这是我的xml文件的摘录 当我生成xsd文件时,它看起来是这样的XML架构验证-验证相同参数名称上的属性值,xml,xsd,Xml,Xsd,我想执行xml模式验证。这是我的xml文件的摘录 当我生成xsd文件时,它看起来是这样的 <xs:complexType name="parameterType" mixed="true"> <xs:sequence> <xs:element type="propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence&g
<xs:complexType name="parameterType" mixed="true">
<xs:sequence>
<xs:element type="propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional"/>
<xs:attribute type="xs:string" name="locked" use="optional"/>
</xs:complexType>
<xs:complexType name="listenerType" mixed="true">
<xs:sequence>
<xs:element type="propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="class" use="optional"/>
<xs:attribute type="xs:string" name="name" use="optional"/>
<xs:attribute type="xs:string" name="locked" use="optional"/>
</xs:complexType>
我的问题是我想通过施加限制来验证每个标记属性值。对于“ip”,请检查值true是否包含某些字符,如“$”,对于地址值“calo”,请检查是否包含相同的字符$
我使用过类似的东西,但它只验证属性的名称。例如:ip-ok,i$p-错误
<xs:attribute name="name" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[^$]*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
我想要验证的是值,而不是属性的名称。不是名称“address”,而是值-“calo”包含“$”,是否仍要执行此操作 在您的案例中,只要parameterType包含子元素propertyType,您就不能这样做
如果parameterType不包含任何子元素,则可以对其内容声明如下限制:
<xs:simpleType name="propertyString">
<xs:restriction base="xs:string">
<xs:pattern value="[^$]*"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="propertyType">
<xs:simpleContent>
<xs:extension base="propertyString">
<xs:attribute type="xs:string" name="name" use="optional"/>
<xs:attribute type="xs:string" name="locked" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
请注意,根据其中一个属性的值,不可能有不同的限制
<xs:simpleType name="propertyString">
<xs:restriction base="xs:string">
<xs:pattern value="[^$]*"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="propertyType">
<xs:simpleContent>
<xs:extension base="propertyString">
<xs:attribute type="xs:string" name="name" use="optional"/>
<xs:attribute type="xs:string" name="locked" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>