0 .. *具有“任何”子元素的任何顺序中的子元素

时间:2012-05-15 17:19:39

标签: xsd

我正试图以任何顺序拥有这些子元素。但我也想要允许任何其他元素。当我添加一个未在选择列表中定义的新元素时,我收到验证错误“元素下不允许元素。”

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://www.w3.org/2005/Atom" elementFormDefault="qualified" 
    attributeFormDefault="unqualified"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:annotation>
        <xsd:documentation>
                This version of the Atom schema is based on version 1.0 of the format specifications,
                found here http://www.atomenabled.org/developers/syndication/atom-format-spec.php.
            </xsd:documentation>
    </xsd:annotation>
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd" />
    <xsd:annotation>
        <xsd:documentation>
            An Atom document may have two root elements, feed and entry, as defined in section 2.
        </xsd:documentation>
    </xsd:annotation>
    <xsd:element name="feed" type="atom:feedType"/>
    <xsd:element name="entry" type="atom:entryType"/>

...

<xsd:complexType name="feedType">
        <xsd:annotation>
            <xsd:documentation>
                The Atom feed construct is defined in section 4.1.1 of the format spec.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:choice minOccurs="3" maxOccurs="unbounded">
            <xsd:element name="author" type="atom:personType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="category" type="atom:categoryType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="contributor" type="atom:personType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="generator" type="atom:generatorType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="icon" type="atom:iconType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="id" type="atom:idType" minOccurs="1" maxOccurs="1" />
            <xsd:element name="link" type="atom:linkType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="logo" type="atom:logoType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="rights" type="atom:textType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="subtitle" type="atom:textType" minOccurs="0" maxOccurs="1" />
            <xsd:element name="title" type="atom:textType" minOccurs="1" maxOccurs="1" />
            <xsd:element name="updated" type="atom:dateTimeType" minOccurs="1" maxOccurs="1" />
            <xsd:element name="entry" type="atom:entryType" minOccurs="0" maxOccurs="unbounded" />
            <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:choice>
        <xsd:attributeGroup ref="atom:commonAttributes"/>
    </xsd:complexType> 

1 个答案:

答案 0 :(得分:1)

默认情况下,

<xsd:any>不允许您在文档中放置任何旧的guff。它仍然需要解析器具有该元素的模式,并且必须针对该模式进行验证。

如果要禁用该元素的验证,请使用processContents="skip",即

<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="skip"/>

MSDN上有processContents的良好描述,并且它比不可穿透的XML Schema规范更清晰。