多个同名、不同类型的元素出现在模型组中 [英] Multiple elements with same name , with different types, appear in the model group

查看:24
本文介绍了多个同名、不同类型的元素出现在模型组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了我遇到的问题,但现在我显示了所有代码xml文件

i write about problem that i have but now i show all code xml file

<?xml version="1.0"?>
<Purchase    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://NamespaceTest.com/Purchase Main.xsd"
               xmlns="http://NamespaceTest.com/Purchase">

  <element style="ide">it can't contain other elements</element>
  <element style="rem">it can contain some other <subelement>elements</subelement></element>
  <element style="rem"> this style can contain other<subelement> elements</subelement></element>
</Purchase>

和 Main.xsd 文件

and Main.xsd file

<?xml version="1.0" encoding="utf-16"?>
<xs:schema elementFormDefault="qualified"
           targetNamespace="http://NamespaceTest.com/Purchase"
           xmlns:pur="http://NamespaceTest.com/Purchase"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Purchase">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="pur:ide_group" maxOccurs="1"/>
        <xs:group ref="pur:rem_group"  maxOccurs="2" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>


  <xs:group name="ide_group">
    <xs:sequence>
      <xs:element name="element" type="pur:ide_type"/>
    </xs:sequence>
  </xs:group>
  <xs:complexType name="ide_type" mixed="true">
    <xs:attribute name="style" type="pur:ide_list"/>
  </xs:complexType>
  <xs:simpleType name="ide_list">
    <xs:restriction base="xs:token">
      <xs:enumeration value="ide"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:group name="rem_group">
    <xs:sequence>
      <xs:element name="element" type="pur:rem_type"/>
    </xs:sequence>
  </xs:group>
  <xs:complexType name="rem_type" mixed="true">
    <xs:sequence>
      <xs:element name="subelement"/>
    </xs:sequence>
    <xs:attribute name="style" type="pur:rem_list"/>
  </xs:complexType>
  <xs:simpleType name="rem_list">
    <xs:restriction base="xs:token">
      <xs:enumeration value="rem"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

我有错误:cos-element-consistent:类型#AnonType_Purchase"的错误.具有不同类型的名称为元素"的多个元素出现在模型组中.我的问题是 xml 文件具有名称相同但样式不同的元素,我需要制定依赖于元素样式的规则.

i have error: cos-element-consistent: Error for type '#AnonType_Purchase'. Multiple elements with name 'element', with different types, appear in the model group. my problem is that xml file have elements with same name but different style, and i need make rule that depend on style of element.

推荐答案

您有几个选择:

  • 如果您可以使用 XSD 1.1,您可以使用条件类型赋值或断言对具有相同名称和声明类型的同级元素施加不同的约束.

  • If you can use XSD 1.1, you may be able to use either conditional type assignment or assertions to impose distinct constraints on sibling elements with the same name and declared type.

您可以修改 XML 的设计,为您拥有的不同元素类型使用不同的元素类型名称.(显然它们是不同的元素类型:您想为它们分配不同的类型.既然它们不同,为什么要使用相同的名称?)

You can modify the design of your XML to use different element type names for the different element types you have. (Clearly they are different element types: you want to assign different types to them. Why call them by the same name, given that they are different?)

使用 XSD 不能做的是声明不同类型的同名同级元素;该语言要求通过仅考虑从验证根到元素的路径来确定任何元素的声明类型.

What you cannot do, with XSD, is declare sibling elements of the same name with different types; the language requires that the declared type of any element be determinable by considering just the path from the validation root to the element.

这篇关于多个同名、不同类型的元素出现在模型组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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