XML架构:“发现无效内容”
我有一个data.xml模式代码:XML架构:“发现无效内容”,xml,xmlschemaset,Xml,Xmlschemaset,我有一个data.xml模式代码: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com" elementFormDefault="qualified"> <xs:element name="data"> <xs:complexType> <xs:sequence>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com" elementFormDefault="qualified">
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="1">
</xs:element>
<xs:element name="type" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="header"/>
<xs:enumeration value="normal"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="backgroundcolor" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="#[0-9A-Fa-f]+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="fontcolor" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="#[0-9A-Fa-f]+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我有一个test.xml文件:
我想要0到无穷多个项目
每个项目可以包含定义的每个子元素的0-1个,例如title和fontcolor
虽然我已经通过一些rrros工作过,但我对模式还不熟悉,所以我边走边学,在各种XSD验证工具中发现了一个奇怪错误的bi:
发现以元素“j:type”开头的无效内容。没有孩子
此时应为元素
使用而不是允许子元素的混合顺序
<?xml version="1.0" encoding="UTF-8"?>
<j:data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jeresapp.dk data.xsd" xmlns:j="http://example.com">
<j:item>
<j:title>test title</j:title>
<j:backgroundcolor>#aaf8941e</j:backgroundcolor>
<j:fontcolor>#ffffff</j:fontcolor>
<j:type>header</j:type>
</j:item>
</j:data>