我做了一个快速测试;从 XML 中创建了一个 XSD 并添加了您的约束:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="parameters">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="add">
<xsd:complexType>
<xsd:attribute name="name" type="NonEmptyString" use="required"/>
<xsd:attribute name="value" type="xsd:unsignedByte" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="NonEmptyString">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
我已经验证了这个 XML:
<parameters>
<add name="" value="1" />
<add name="two" value="2" />
</parameters>
我有这个错误:
Error occurred while loading [], line 2 position 8
The 'name' attribute is invalid - The value '' is invalid according to its datatype 'NonEmptyString' - The actual length is less than the MinLength value.
我会说问题在于您的 XSD 处理器,而不是 XSD 本身。也许您可以使用您正在使用的处理器更新帖子?