【问题标题】:How to define price data range via XSD restriction如何通过 XSD 限制定义价格数据范围
【发布时间】:2014-04-24 23:37:26
【问题描述】:

我很难对 XML 标记进行限制。

XML 标签名称 = 价格,价值 = 150 美元

限制:价格必须包含一个“$”,后跟一个介于 0 和 400 之间的浮点数。

我需要具有上述限制的价格的 XSD 定义。

【问题讨论】:

    标签: xml regex xsd


    【解决方案1】:

    这个 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>
    

    【讨论】:

    • 非常感谢!这有帮助!
    猜你喜欢
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 2019-02-17
    • 2021-12-26
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多