加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

这个XML Schema有什么根本错误吗?

发布时间:2020-12-16 07:41:18 所属栏目:百科 来源:网络整理
导读:我对 XML Schema只有基本的了解.这基本上是我第一次以任何严肃的方式与他们互动而且我遇到了一些问题.我已经阅读了谷歌上的XSD,所有内容都可以看到这个文件. xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xs:element name="credits" xs:complexTy
我对 XML Schema只有基本的了解.这基本上是我第一次以任何严肃的方式与他们互动而且我遇到了一些问题.我已经阅读了谷歌上的XSD,所有内容都可以看到这个文件.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="credits">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="property" maxOccurs="16" minOccurs="13" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="property" type="xs:string">    
    <xs:complexType>        
        <xs:sequence>            
            <xs:element ref="item" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute ref="name" use="required"/>
    </xs:complexType>

  </xs:element>

  <xs:element name="item" type="xs:string"/>

  <xs:attribute name="name" type="xs:string">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="example1"/>
          <xs:enumeration value="example2"/>
          <xs:enumeration value="example3"/>
          <xs:enumeration value="example4"/>
          <xs:enumeration value="example5"/>
          <xs:enumeration value="example6"/>
          <xs:enumeration value="example7"/>
          <xs:enumeration value="example8"/>
          <xs:enumeration value="example9"/>
          <xs:enumeration value="example10"/>
          <xs:enumeration value="example11"/>
          <xs:enumeration value="example12"/>
          <xs:enumeration value="example13"/>
          <xs:enumeration value="example14"/>
          <xs:enumeration value="example15"/>
          <xs:enumeration value="example16"/>
        </xs:restriction>
      </xs:simpleType>
  </xs:attribute>

</xs:schema>

这是我加载它的方式:

SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
Schema schemaXSD = schemaFactory.newSchema( new File ( "test.xsd" ) );

我得到如下例外:

org.xml.sax.SAXParseException:
src-element.3: Element ‘property’ has
both a ‘type’ attribute and a
‘anonymous type’ child. Only one of
these is allowed for an element.

谢谢你的帮助!关于阅读/使用他人创建的模式的任何一般建议也表示赞赏! :d

这个位是你的问题代码:
<xs:element name="property" type="xs:string">    
    <xs:complexType>        
        <xs:sequence>            
            <xs:element ref="item" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute ref="name" use="required"/>
    </xs:complexType>

  </xs:element>

要么删除外部元素上的类型(type =“xs:string”),要么删除匿名内部complexType元素(< xs:complexType> …< / xs:complexType>)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读