如何通过 XSD 限制定义价格数据范围 [英] How to define price data range via XSD restriction
本文介绍了如何通过 XSD 限制定义价格数据范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难对 XML 标签进行限制.
I am having a hard time doing a restriction for an XML tag.
XML 标签名称 = 价格,价值 = 150 美元
XML tag name = price, value = $150
限制:价格必须包含一个$",后跟一个 0 到 400 之间的浮点数.
我需要具有上述限制的价格的 XSD 定义.
I need an XSD definition for price with the above restriction.
推荐答案
此 XSD:
<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="prices">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="price" maxOccurs="unbounded">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\$[1-3]?[0-9]?[0-9]?(\.[0-9][0-9])?|(\$400(\.00)?)"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
允许以下价格:
<?xml version="1.0" encoding="utf-8" ?>
<prices>
<price>$0</price>
<price>$1</price>
<price>$1.00</price>
<price>$1.99</price>
<price>$400.00</price>
<price>$400</price>
<price>$.99</price>
</prices>
这篇关于如何通过 XSD 限制定义价格数据范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文