XmlSchemaValidationException 元素不能包含空格



>当我尝试验证XML方案时,出现以下异常:

System.Xml.Schema.XmlSchemaValidationException: 'The element cannot contain white space. Content model is empty.'

我正在阅读相同的错误,但我似乎无法在这些帖子中找到解决方案。

  • 验证 XML 内容时出错:元素不能包含空格。内容模型为空
  • 错误"元素不能包含空格。内容模型是空的。

谁能告诉我我做错了什么,为什么?

XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="urn://Test.Deploy" elementFormDefault="qualified" xmlns="urn://Test.Deploy" xmlns:mstns="urn://Test.Deploy" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="configuration">
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="deployDir" type="xs:anyURI" use="optional"  default="xs:"/>
</xs:complexType>
<xs:complexType name="service">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="order" type="xs:string" use="optional" />
<xs:attribute name="version" type="xs:string" use="optional" />
</xs:complexType>
<xs:complexType name="services">
<xs:sequence>
<xs:element name="service" type="service" minOccurs="0" nillable="true" />
</xs:sequence>
<xs:attribute name="environment" use="required" />
<xs:attribute name="version" use="required" />
</xs:complexType>
<xs:element name="configuration" type="configuration"/>
<xs:element name="services" type="services" />
</xs:schema>

.XML:

<?xml version="1.0" encoding="utf-8"?> 
<configuration xmlns="urn://Test.Deploy" id="Test deploy" description="Test deploy server" deployDir="../Deploy">
<services environment="Development" version="0.1796.0">
<service name="Foo" order="0" />
<service name="Bar" />
</services>
</configuration>

您可以将 XSD 更改为:

<xs:schema targetNamespace="urn://Test.Deploy" elementFormDefault="qualified" xmlns="urn://Test.Deploy" xmlns:mstns="urn://Test.Deploy" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="configuration">
<xs:sequence>
<xs:element ref="services" minOccurs="1"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="deployDir" type="xs:anyURI" use="optional"  default="xs:"/>
</xs:complexType>
<xs:complexType name="service">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="order" type="xs:string" use="optional" />
<xs:attribute name="version" type="xs:string" use="optional" />
</xs:complexType>
<xs:complexType name="services">
<xs:sequence>
<xs:element name="service" type="service" minOccurs="0" maxOccurs="unbounded" nillable="true" />
</xs:sequence>
<xs:attribute name="environment" use="required" />
<xs:attribute name="version" use="required" />
</xs:complexType>
<xs:element name="configuration" type="configuration"/>
<xs:element name="services" type="services" />
</xs:schema>

您错过了对configurationservices的引用和services中的maxOccurs="unbounded"

相关内容

  • 没有找到相关文章

最新更新