urac 2019-05-27 13:18 采纳率: 0%
浏览 361
已结题

XSD 如何先HTML一样通过input的类型不同区分属性或者子元素的不同

目前设计的XML格式如下:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <div name ="项目信息" type="TabPage">
    <control name ="项目名称" type="TextBox" defaultvalue=""/>
    <control name="项目类型" type="DropDown">
      <item index="1" name ="A" value ="A"> </item>
      <item index="2" name ="B" value ="B"> </item>
      <item index="3" name ="C" value ="C"> </item>
    </control>
  </div>
  <div name ="项目基本信息" type="TabPage">
    <control name ="项目名称" type="TextBox" defaultvalue=""/>
    <control name="项目类型" type="DropDown">
      <item index="1" name ="A" value ="A"> </item>
      <item index="2" name ="B" value ="B"> </item>
      <item index="3" name ="C" value ="C"> </item>
    </control>
  </div>
</root>

同样的control包含不同的类型,TextBox没有子项,DropDown有下拉列表子项.尝试写XSD来限制,但是遇到如下报错:
图片说明

XSD代码如下:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!-- 简易元素的定义 -->
  <!-- 属性的定义 -->
  <!-- 简单类型的定义(通用) -->
  <xs:simpleType name="StringNotEmpty">
    <xs:restriction base="xs:string">
      <xs:pattern value=".+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="IntStartFrom1">
    <xs:restriction base="xs:int">
      <xs:minInclusive value="1"></xs:minInclusive>
    </xs:restriction>
  </xs:simpleType>
  <!-- 简单类型的定义(指定类型) -->
  <xs:simpleType name="DivTypeTabPage">
    <xs:restriction base="xs:string">
      <xs:pattern value="TabPage"></xs:pattern>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="DivTypeExcel">
    <xs:restriction base="xs:string">
      <xs:pattern value="Excel"></xs:pattern>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="DivTypeLogic">
    <xs:restriction base="xs:string">
      <xs:pattern value="logic"></xs:pattern>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="DivTypeBackUp">
    <xs:restriction base="xs:string">
      <xs:enumeration value="TabPage"/>
      <xs:enumeration value="Excel"/>
      <xs:enumeration value="logic"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ControlTypeTextBox">
    <xs:restriction base="xs:string">
      <xs:pattern value="TextBox"></xs:pattern>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ControlTypeDropDown">
    <xs:restriction base="xs:string">
      <xs:pattern value="DropDown"></xs:pattern>
    </xs:restriction>
  </xs:simpleType>

  <!-- 属性组 -->
  <xs:attributeGroup name="AGDivTabPage">
    <xs:attribute name="name" type="StringNotEmpty"></xs:attribute>
    <xs:attribute name="type" type="DivTypeTabPage"></xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="AGControlTextBox">
    <xs:attribute name="name" type="StringNotEmpty" ></xs:attribute>
    <xs:attribute name="type" type="ControlTypeTextBox"></xs:attribute>
    <xs:attribute name="defaultvalue" type="xs:string" ></xs:attribute>
    <xs:attribute name="propertytype" type="xs:string" ></xs:attribute>
    <xs:attribute name="propertyid" type="xs:int" ></xs:attribute>
    <xs:attribute name="propertyname" type="xs:string" ></xs:attribute>
    <xs:attribute name="propertyindex" type="xs:int" default="0"></xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="AGControlDropDown">
    <xs:attribute name="name" type="StringNotEmpty"></xs:attribute>
    <xs:attribute name="type" type="ControlTypeDropDown"></xs:attribute>
    <xs:attribute name="defaultvalue" type="xs:string" ></xs:attribute>
  </xs:attributeGroup>

  <xs:attributeGroup name="AGControlDropDownItem">
    <xs:attribute name="index" type="IntStartFrom1"></xs:attribute>
    <xs:attribute name="name" type="xs:string"></xs:attribute>
    <!--检查代码是否需要唯一性-->
    <xs:attribute name="value" type="xs:string" ></xs:attribute>
  </xs:attributeGroup>

  <!-- 元素组 -->
  <xs:group name="EGControlTextBox">
    <xs:sequence>
      <xs:element name="control" >
        <xs:complexType>
          <xs:attributeGroup ref="AGControlTextBox"></xs:attributeGroup>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:group>

  <xs:group name="EGControlDropDown">
    <xs:sequence>
      <xs:element name="control">
        <xs:complexType>
          <xs:group ref="EGControlDropDownItem" minOccurs="1" maxOccurs="unbounded"></xs:group>
          <xs:attributeGroup ref="AGControlDropDown"></xs:attributeGroup>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:group>

  <xs:group name="EGControlDropDownItem">
    <xs:sequence>
      <xs:element name="item">
        <xs:complexType>
          <xs:group ref="EGControlDropDown" minOccurs="0" maxOccurs="1"></xs:group>
          <xs:attributeGroup ref="AGControlDropDownItem"></xs:attributeGroup>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:group>


  <xs:group name="EGDivTabPage">
    <xs:sequence>
      <xs:element name="div" maxOccurs="unbounded">
        <xs:complexType>
          <xs:choice>
            <xs:group ref="EGControlTextBox" maxOccurs="unbounded" minOccurs="0"></xs:group>
            <xs:group ref="EGControlDropDown" maxOccurs="unbounded" minOccurs="0"></xs:group>
          </xs:choice>
          <xs:attributeGroup ref="AGDivTabPage"></xs:attributeGroup>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:group>
  <!-- 复合元素的定义 -->
  <!-- 根元素的定义-->
  <xs:element name="root">
    <xs:complexType>
      <xs:choice>
        <xs:group ref="EGDivTabPage" maxOccurs="unbounded" minOccurs="1"></xs:group>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

[code=xml]

[/code]

报错原因是98行和88行定义了相同的control元素,目的是通过不同的元素组来区分不同的control.

但是出现如图片报错,还请各位帮忙看看!

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-05-27 14:02
    关注

    https://ask.csdn.net/questions/763193
    可以看xhtml的xsd定义

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向