以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  Schema中如何实现循环引用,在线急等~  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=58109)


--  作者:lytom318
--  发布时间:1/16/2008 2:20:00 PM

--  Schema中如何实现循环引用,在线急等~
此Schema是来验证一个树型结果的xml,如菜单.每个tree结构都是一样的,但怎么实现嵌套呢,有的tree是父节点,有的是子节点,有的既是父节点,又是子节点.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:element name="Menus">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Menu" maxOccurs="unbounded">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="groupList" type="xs:string" maxOccurs="unbounded"/>
       <xs:element name="userList" type="xs:string" maxOccurs="unbounded"/>
       <xs:element name="Menu" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="groupList" type="xs:string" maxOccurs="unbounded"/>
          <xs:element name="userList" type="xs:string" maxOccurs="unbounded"/>
         </xs:sequence>
         <xs:attribute name="id" type="xs:int" use="required"/>
         <xs:attribute name="child">
          <xs:simpleType>
           <xs:restriction base="xs:int">
            <xs:enumeration value="0"/>
            <xs:enumeration value="1"/>
           </xs:restriction>
          </xs:simpleType>
         </xs:attribute>
         <xs:attribute name="name" type="xs:string"/>
         <xs:attribute name="father" type="xs:int" default="0"/>
         <xs:attribute name="imageURL" type="xs:string"/>
         <xs:attribute name="linkURL" type="xs:string"/>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
      <xs:attribute name="id" type="xs:int" use="required"/>
      <xs:attribute name="child">
       <xs:simpleType>
        <xs:restriction base="xs:int">
         <xs:enumeration value="0"/>
         <xs:enumeration value="1"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="name" type="xs:string"/>
      <xs:attribute name="father" type="xs:int" default="0"/>
      <xs:attribute name="imageURL" type="xs:string"/>
      <xs:attribute name="linkURL" type="xs:string"/>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>
但我这个不是无限的啊 怎么实现无限级的呢 以为菜单用户可以直接无限加撒
--  作者:waoywssy
--  发布时间:1/22/2008 12:21:00 PM

--  
刚回答了一个帖子;
同样的答案希望对你有用,这里的Menu就是可以嵌套的:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema        targetNamespace="menus"
                  elementFormDefault="qualified"
                  xmlns="menus"
                  xmlns:mstns="menus"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  >
  <xs:element name="Menus">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Menu" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="Menu">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="groupList" type="xs:string"/>
        <xs:element name="userList" type="xs:string"/>
          <xs:element ref="Menu" maxOccurs="1" minOccurs="0"/>
      </xs:sequence>
      <xs:attributeGroup ref="att"/>
    </xs:complexType>
  </xs:element>

  <xs:attributeGroup name="att">
    <xs:attribute name="id" type="xs:integer"/>
    <xs:attribute name="name" type="xs:string"/>
    <xs:attribute name="hasChildren" type="xs:boolean"/>
    <xs:attribute name="father" type="xs:integer"/>
    <xs:attribute name="imgURL" type="xs:anyURI"/>
    <xs:attribute name="linkURL" type="xs:anyURI"/>
  </xs:attributeGroup>
  
</xs:schema>


--  作者:waoywssy
--  发布时间:1/22/2008 12:22:00 PM

--  
我晕,我发现了,刚回答的问题也是你N天后提出的......我成灌水的了......
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
61.523ms