自定义XSD对XML校验,eclipse校验出现如下错误:
XML内容:
<PrimaryKey>123456</PrimaryKey>
错误提示:
Element must have no character or element information item [children], because the type's content type is empty
修改前的XSD定义:
<xs:element name="PrimaryKey" type="KeyType" nillable="false" maxOccurs="15"/>
<xs:complexType name="KeyType">
<xs:attribute name="type" default="STRING" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="\d+" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
将 KeyType修改为继承自xs:string后通过。
<xs:complexType name="KeyType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" default="STRING" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="\d+" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
参考文档:http://stackoverflow.com/questions/4432183/xml-schema-definition-problem

本文介绍了一种XML文件使用自定义XSD进行校验时遇到的问题及解决方案。错误提示表明元素内容为空,通过调整XSD中KeyType的定义为继承自xs:string解决了这一问题。

292

被折叠的 条评论
为什么被折叠?



