Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml xsd中的递归_Xml_Recursion_Xsd - Fatal编程技术网

Xml xsd中的递归

Xml xsd中的递归,xml,recursion,xsd,Xml,Recursion,Xsd,如何使用预定义的complexType在xsd模式中进行递归,如下所示: <xs:complexType name="style"> <xs:attribute name="name" type="xs:string" use="optional" /> <xs:attribute name="color" type="xs:string" use="optional" /> </xs:complexType>

如何使用预定义的complexType在xsd模式中进行递归,如下所示:

  <xs:complexType name="style">
      <xs:attribute name="name" type="xs:string" use="optional" />
      <xs:attribute name="color" type="xs:string" use="optional" />
  </xs:complexType>

    <xs:complexType name="children">
      <xs:sequence>
        <xs:element name="div" type="style">
          <xs:complexType>
            <xs:sequence>
              <xs:element ref="children" minOccurs="0"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>

如果希望以下XML有效

<?xml version="1.1" encoding="utf-8" ?>
<children xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="try.xsd">
  <div name="John" color="red">
    <children>
      <div name="Mary" color="white"/>
      <div name="Fred" color="blue"/>
    </children>
  </div>
</children>

然后,这个递归XSD将符合要求:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
  <xs:element name="children">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="div" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element ref="children" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="optional" />
            <xs:attribute name="color" type="xs:string" use="optional" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


请发布您希望根据XSD有效的示例XML。
请记住,每个元素都可以有这样的树,不仅是div。而且,每个元素都应该有像
这样的属性,这会起作用,但问题是,我在样式中有很多属性,还有很多元素(不仅仅是div)。这只是个例子,但我需要整个机制。我将从工作中提供更好的作用域。许多属性和元素不会从根本上改变递归。当然,如果有机会,请展示一个您希望介绍的XML的代表性示例,更新解决方案以满足您的需要是没有问题的。当您查看我的示例XML时,模式看起来非常糟糕,但我最终使用了这种方法。