cvc-complex-type.2.3:元素“group"不能有字符 [children],因为该类型的内容类型是 element-only [英] cvc-complex-type.2.3: Element 'group' cannot have character [children], because the type's content type is element-only

查看:22
本文介绍了cvc-complex-type.2.3:元素“group"不能有字符 [children],因为该类型的内容类型是 element-only的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从这个 XSD 创建 XML:

 <?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="group">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="person" minOccurs="5" maxOccurs="20" type="xs:string"/>
            </xs:sequence>
            <xs:attribute name="name" use="required" type="xs:string"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

这是我尝试过的 XML:

<?xml version="1.0" ?>
<group name="abcd">
    xmlns="www.example.org"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="ex1.xsd">
    <person>Joao</person>
    <person>Andre</person>
    <person>Filipe</person>
    <person>Joaquim</person>
    <person>Rui</person>
</group>

我收到此错误:

无效.错误 - 第 10、9 行:org.xml.sax.SAXParseException;行号:10;列数:9;cvc-complex-type.2.3:元素group"不能有字符 [children],因为该类型的内容类型是 element-only.

Not valid. Error - Line 10, 9: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 9; cvc-complex-type.2.3: Element 'group' cannot have character [children], because the type's content type is element-only.

推荐答案

问题数量:

  • 正如 Filburt 提到的,您过早地关闭了开放的标签.这是您立即出错的直接原因.它导致解析器将您打算作为文本的属性误解为文本group 元素的内容.
  • schemaLocation 必须采用命名空间-XSD pairs.
  • elementFormDefault="qualified"
  • As Filburt mentioned, you've prematurely closed the opening group tag. This is the direct cause of your immediate error. It causes the parser to misinterpret what you intend to be attributes as text content to the group element.
  • schemaLocation must take namespace-XSD pairs.
  • elementFormDefault="qualified"
  • etc.

总的来说,以下 XSD 将成功验证以下 XML.

Altogether, the following XSD will validate the following XML successfully.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.example.org"
           elementFormDefault="qualified">
  <xs:element name="group">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="person" minOccurs="5" maxOccurs="20" type="xs:string"/>
      </xs:sequence>
      <xs:attribute name="name" use="required" type="xs:string"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

XML

<?xml version="1.0" ?>
<group name="abcd"
       xmlns="http://www.example.org"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.example.org ex1.xsd">
  <person>Joao</person>
  <person>Andre</person>
  <person>Filipe</person>
  <person>Joaquim</person>
  <person>Rui</person>
</group>

这篇关于cvc-complex-type.2.3:元素“group"不能有字符 [children],因为该类型的内容类型是 element-only的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆