XML Schema anyAttribute 元素


XML Schema 參考手冊 完整 XML Schema 參考手冊

定義和用法

anyAttribute 元素使創作者可以通過未被 schema 規定的屬性來擴展 XML 文檔。

元素資訊

  • 父元素: complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent), attributeGroup

語法

<anyAttribute
id=ID
namespace=namespace
processContents=lax|skip|strict
any attributes
>

(annotation?)

</anyAttribute>

(? 符號聲明該元素可在 anyAttribute 元素內出現零次或一次。)

屬性 描述
id 可選。規定該元素的唯一的 ID。
namespace

可選。規定包含可以使用的元素的命名空間。如果沒有指定命名空間,則 ##any 為默認值。如果指定命名空間,則必須是以下值之一。

  • ##any - 來自任何命名空間的元素都可以出現(默認)。
  • ##other - 來自該元素的父元素的目標命名空間之外的任何命名空間的元素都可以出現。
  • ##local - 未由命名空間限定的元素可以出現。
  • ##targetNamespace - 來自包含該元素的父元素的目標命名空間的元素可以出現。
  • {URI references of namespaces, ##targetNamespace, ##local} 的列表 - 來自通過空格分隔的命名空間列表的元素可以出現。 該列表可以包含以下內容: 命名空間 ##targetNamespace 和 ##local 的 URI 引用。
processContents

可選。一個指示符,指示應用程式或 XML 處理器應如何根據由該 any 元素指定的元素處理 XML 文檔的驗證。 如果沒有指定 processContents 屬性,則默認為 strict。 如果指定了 processContents,必須是以下值之一。

  • strict - XML 處理器必須獲得所需命名空間的架構,並且必須驗證來自這些命名空間的所有元素。(默認)
  • lax - 與 strict 相同;但是,即使不能獲取該架構,也不會發生任何錯誤。
  • skip - XML 處理器不嘗試驗證來自指定命名空間的所有元素。
any attributes

可選。規定帶有 non-schema 命名空間的任何其他屬性。

實例 1

下麵的例子展示了針對 "person" 元素的一個聲明。通過使用 元素,創作者能夠向 "person" 元素添加任意數量的屬性:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
    <xs:anyAttribute/>
  </xs:complexType>
</xs:element>


XML Schema 參考手冊 完整 XML Schema 參考手冊