Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
C# Xml验证错误根据其数据类型,该值无效';复制自';-枚举约束失败_C#_Xml_Validation - Fatal编程技术网

C# Xml验证错误根据其数据类型,该值无效';复制自';-枚举约束失败

C# Xml验证错误根据其数据类型,该值无效';复制自';-枚举约束失败,c#,xml,validation,C#,Xml,Validation,我正在尝试验证一个Xml文件 我的xsd架构片段: <xs:attribute name="PostIndex" use="optional"> <xs:annotation> <xs:documentation>Post Index</xs:documentation> </xs:annot

我正在尝试验证一个Xml文件

我的xsd架构片段:

<xs:attribute name="PostIndex" use="optional">
                        <xs:annotation>
                            <xs:documentation>Post Index</xs:documentation>
                        </xs:annotation>
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:length value="6"/>
                                <xs:pattern value="\d{0}|\d{6}"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
<Atr1>
<Atr2 Atr="A9F130BE-3974-4698-B9F9-72037BC0E97F" PostIndex="123456" />
<Atr2 Atr3="123" Atr4="11111" />
</Atr1>

邮政索引
XML文件片段:

<xs:attribute name="PostIndex" use="optional">
                        <xs:annotation>
                            <xs:documentation>Post Index</xs:documentation>
                        </xs:annotation>
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:length value="6"/>
                                <xs:pattern value="\d{0}|\d{6}"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
<Atr1>
<Atr2 Atr="A9F130BE-3974-4698-B9F9-72037BC0E97F" PostIndex="123456" />
<Atr2 Atr3="123" Atr4="11111" />
</Atr1>

当我运行验证代码时,它通过了架构验证。我有错误:

“PostIndex”属性无效-值“123456”无效 根据其数据类型“String”-枚举约束 失败了


这是我使用的XSD和XML,它工作得很好。因此,请发布您的整个XSD和XML

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="computer">
    <xs:annotation>
      <xs:documentation xml:lang="it-IT">Definizione di un computer</xs:documentation>
      <xs:documentation xml:lang="en-US">Definition of a computer</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:attribute name="PostInt">
        <xs:simpleType>
          <xs:restriction base="xs:string">
           <xs:length value="6"/>
           <xs:pattern value="\d{0}|\d{6}"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>
</xs:schema>

计算机定义
计算机的定义
XML



我使用了下面的方法

如果你添加一个非数字值,比如“string”,它是否有效?您是否应该使用
xs:integer
?如果添加非数值,我有另一个错误-属性无效-值'qwerty'根据其数据类型'String'无效-模式约束失败\d=[0-9],所以您想要0-9,但作为字符串?我已检查您的xsd并正确验证。你能不能把整个xml和xsd都放进去,我需要模式的字符串谢谢,我正在尝试在线验证我的xsd和xml,它是有效的。我认为我的验证器工作不正确