自定义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