我正在尝试验证 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>
XML 文件片段:
<Atr1>
<Atr2 Atr="A9F130BE-3974-4698-B9F9-72037BC0E97F" PostIndex="123456" />
<Atr2 Atr3="123" Atr4="11111" />
</Atr1>
当我运行验证代码时,它通过了模式验证我有错误:
The 'PostIndex' attribute is invalid - The value '123456' is invalid according to its datatype 'String' - The Enumeration constraint failed.
最佳答案
这是我使用的 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
<computer PostInt="123456" />
我使用了以下 online validator
关于c# - Xml 验证错误根据其数据类型 'CopyFrom',该值无效 - 枚举约束失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18575144/