Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 每周1天或以上的XSD限制_Regex_Xml_Xsd - Fatal编程技术网

Regex 每周1天或以上的XSD限制

Regex 每周1天或以上的XSD限制,regex,xml,xsd,Regex,Xml,Xsd,我试图使用模式匹配来匹配一个元素,该元素列出了一周中某一天的1到7个短名称。我尝试在在线工具中创建一个匹配的模式,但在XSD中进行验证时失败 元素可以进入的示例方式 <DayOfWeek>Mon Tue Wed Thu Fri Sat Sun </DayOfWeek> <DayOfWeek>Mon Wed Fri </DayOfWeek> 在以下simpleType中应用时: <xs:simpleType name="ValidDays"&

我试图使用模式匹配来匹配一个元素,该元素列出了一周中某一天的1到7个短名称。我尝试在在线工具中创建一个匹配的模式,但在XSD中进行验证时失败

元素可以进入的示例方式

<DayOfWeek>Mon Tue Wed Thu Fri Sat Sun </DayOfWeek>
<DayOfWeek>Mon Wed Fri </DayOfWeek>
在以下simpleType中应用时:

<xs:simpleType name="ValidDays">
    <xs:restriction base="xs:token">
        <xs:pattern value="(Mon[ ]+)?(Tue[ ]+)?(Wed[ ]+)?(Thu[ ]+)?(Fri[ ]+)?(Sat[ ]+)?(Sun[ ]+)?" />
    </xs:restriction>
</xs:simpleType>

我甚至尝试从站点应用“/”和“/g”,以防万一,我得到了相同的失败消息。

使用
xs:list
而不是regex来表示枚举值的空格分隔列表:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="DayOfWeek">
    <xs:simpleType>
      <xs:restriction>
        <xs:simpleType>
          <xs:list itemType="ValidDays"/>
        </xs:simpleType>
        <xs:minLength value="1"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
  <xs:simpleType name="ValidDays">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Sun"/>
      <xs:enumeration value="Mon"/>
      <xs:enumeration value="Tue"/>
      <xs:enumeration value="Wed"/>
      <xs:enumeration value="Thu"/>
      <xs:enumeration value="Fri"/>
      <xs:enumeration value="Sat"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

谢谢,处理了需要检查的内容,并在拼写错误、意外使用小写时出错,但允许1个或多个空格。我现在可以用它来代替一个正则表达式来表示我不喜欢的可接受的多小时数,它感觉不够可靠。
<xs:element name="DayOfWeek">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="ValidDays" />
                    </xs:simpleContent>
                </xs:complexType>
                </xs:element>
The 'DayOfWeek' element is invalid - The value 'Mon Tue Wed Thu Fri Sat Sun ' is invalid according to its datatype 'Token' - The Pattern constraint failed.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="DayOfWeek">
    <xs:simpleType>
      <xs:restriction>
        <xs:simpleType>
          <xs:list itemType="ValidDays"/>
        </xs:simpleType>
        <xs:minLength value="1"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
  <xs:simpleType name="ValidDays">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Sun"/>
      <xs:enumeration value="Mon"/>
      <xs:enumeration value="Tue"/>
      <xs:enumeration value="Wed"/>
      <xs:enumeration value="Thu"/>
      <xs:enumeration value="Fri"/>
      <xs:enumeration value="Sat"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>