Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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:包含xs:any的元素的无序列表_Xml_Xsd - Fatal编程技术网

Xml XSD:包含xs:any的元素的无序列表

Xml XSD:包含xs:any的元素的无序列表,xml,xsd,Xml,Xsd,我有一个无序的元素列表,其中包含xs:any,尝试了多种选择和顺序组合,它们都违反了“唯一粒子属性”。 我的xml如下所示: <mall id="Andaal"> <eff>effRecorder</eff> <morr>id</morr> <todd>toddCurrentType == toddIdOldType</todd> <mall id="donAllId">

我有一个无序的元素列表,其中包含xs:any,尝试了多种选择和顺序组合,它们都违反了“唯一粒子属性”。 我的xml如下所示:

<mall id="Andaal">
    <eff>effRecorder</eff>
    <morr>id</morr>
    <todd>toddCurrentType == toddIdOldType</todd>
    <mall id="donAllId">
        <morr>id</morr>
        <eff>effRecorder</eff>
        <other>QuickCode</other>
        <mall id="mall2Id">
            <eff>TickerChainEff</eff>
            <morr>SourceId</morr>
            <other>TickerCode</other>
        </mall>
    </mall>
    <mall id="mall2SourceId">
        <eff>Listing2SourceEff</eff>
        <morr>id</morr>
        <other>other2Price</other>
        <other>ExpiryDate</other>
    </mall>
</mall>

自动记录器
身份证件
toddCurrentType==ToddOldType
身份证件
自动记录器
快速代码
TickerChainEff
源ID
股票代码
列表2资源效率
身份证件
其他2价
过期酸盐
xsd代码:

<xs:element name="mall" maxOccurs="unbounded" minOccurs="0">
    <xs:complexType mixed="true">
        <xs:sequence>
            <xs:element type="xs:string" name="eff" minOccurs="0"/>
            <xs:element type="xs:string" name="todd" minOccurs="0"/>
            <xs:element type="xs:string" name="morr" minOccurs="1"/>
            <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax" />
        </xs:sequence>
        <xs:attribute name="id" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="[A-Za-z_]+"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
</xs:element>


请注意,元素
eff
todd
morr
可以以任何顺序出现,并且它们可以出现在另一个
mall
元素内部的层次结构中

XSD 1.0

使用XSD1.0这是不可能的。基本上,解析器需要能够提取每个元素,并在给定其当前状态的情况下(明确地)确定应该使用哪个模式元素来验证它。它不支持任何形式的前瞻。通过引入any您提供的模糊性,any将匹配现有的eff、todd、morr元素,这可以通过向前看来解决,但这是不受支持的

所以你得到的最好的就是这个


其中any被约束为不是当前targetnamespace的任何命名空间。这可以防止歧义和一切正常

除了……现在您有了一个允许0-n eff、todd、morr元素的模式。因此,这还远远不够完美

XSD 1.1

使用XSD 1.1和openContent元素,您可以完成您正试图完成的任务


这将强制执行eff、todd和morr上的基数规则,同时允许您将任何其他内容放在它们之间,即

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.7015 (https://www.liquid-technologies.com) -->
<mall xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:noNamespaceSchemaLocation="Schema11.xsd" id="_Mi___XW">
    <OTHER></OTHER>
    <eff>string</eff>
    <OTHER></OTHER>
    <todd>string</todd>
    <OTHER></OTHER>
    <morr>string</morr>
    <OTHER></OTHER>
</mall>

一串
一串
一串
缺点是XSD1.1还不支持widley,Xerces和其他一些解析器支持它,但不多

更新

更新以反映Michael Kay的评论。正如Michael指出的那样,XSD1.1现在可以解决any和命名元素之间的歧义。结果更简单


实际上,XSD 1.1中不需要openContent:模式是可以的,因为特定元素粒子和通配符粒子之间的模糊性是为了特定元素而解决的。
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.7015 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="mall">
        <xs:complexType mixed="true">
            <xs:openContent mode="interleave">
                <xs:any processContents="lax" />
            </xs:openContent>
            <xs:all>
                <xs:element name="eff" type="xs:string" minOccurs="0" />
                <xs:element name="todd" type="xs:string" minOccurs="0" />
                <xs:element name="morr" type="xs:string" minOccurs="1" />
            </xs:all>
            <xs:attribute name="id" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value="[A-Za-z_]+" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
</xs:schema>
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.7015 (https://www.liquid-technologies.com) -->
<mall xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:noNamespaceSchemaLocation="Schema11.xsd" id="_Mi___XW">
    <OTHER></OTHER>
    <eff>string</eff>
    <OTHER></OTHER>
    <todd>string</todd>
    <OTHER></OTHER>
    <morr>string</morr>
    <OTHER></OTHER>
</mall>
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2017 Developer Bundle Edition (Trial) 15.0.0.7015 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="mall">
        <xs:complexType mixed="true">
            <xs:all>
                <xs:element name="eff" type="xs:string" minOccurs="0" />
                <xs:element name="todd" type="xs:string" minOccurs="0" />
                <xs:element name="morr" type="xs:string" minOccurs="1" />
                <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax" />
            </xs:all>
            <xs:attribute name="id" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value="[A-Za-z_]+" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
</xs:schema>