我正在为这个xml构建一个xml架构:
<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="basic.xsd">
<!--Comienza la descripción de los grupos sencillos-->
<!--modificador-->
<group tagName="A">
<name>modificador</name>
<type>simple</type>
<words>
<word>el<word>
<word>este<word>
</words>
</group>
<!--prefijos-->
<group tagName="C">
<name>prefijos</name>
<type>simple</type>
<words>
<word>pre</word>
<word>ante</word>
<word>anti</word>
<word>pro</word>
<word>tri</word>
</words>
</group>
<!--Composiciones de intérvalos-->
</groups>
这是我的xsd文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="name" type="xs:string"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="word" type="xs:string"/>
<!-- definition of attributes -->
<xs:attribute name="tagName" type="xs:ID"/>
<!-- definition of complex elements -->
<xs:element name="words">
<xs:complexType>
<xs:sequence>
<xs:element ref="word" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="type"/>
<xs:element ref="words" />
</xs:sequence>
<xs:attribute ref="tagName" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="groups">
<xs:complexType>
<xs:sequence>
<xs:element ref="group" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我使用nokogiri验证我的xml,但我收到以下错误:
元素&#39;字&#39;:不允许使用元素内容,因为类型定义很简单。 XML不是架构有效
为什么单词要复杂呢?我怎么做到这一点因为对我来说还不错。 谢谢你提前。
答案 0 :(得分:1)
您不小心使用了开始标记,而不是在
处关闭标记<word>el<word>
<word>este<word>
输入XML文件中的。由于没有结束标记,因此XML格式不正确。始终先检查良好状态是一个好主意。
您收到消息&#34;不允许元素内容&#34;因为看起来word
元素中有word
个元素。这只适用于复杂类型。
将输入文件中受影响的行更改为
<word>el</word>
<word>este</word>
并且对您的架构的验证将成功。