2012-05-15 77 views
0

我試圖以任何順序具有這些子元素中的任何一個。但我也想要允許任何其他元素。當我添加一個沒有在選擇列表中定義的新元素時,出現驗證錯誤「元素在元素下不允許」。0 .. *任何訂單中的「任何」子元素的子元素

<?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

<xsd:any>默認不允許你把任何舊的廢話在文檔中。它仍然需要解析器擁有該元素的模式,並且它必須針對該模式進行驗證。

如果要禁用該元素的驗證,然後用processContents="skip",即

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

還有的processContentsMSDN一個很好的說明,這是一個很好的協議比堅不可摧的XML模式規範清晰。

相關問題