nil

一个布尔值,指示元素是否应包含内容。

<xsi:nil="boolean">

  • true
    元素必须为空,并且架构中的元素声明必须具有批注,而且该批注中的 nillable 属性设置为 true

  • false
    元素不能为空。 这是默认值。

示例

本示例使用 XML 架构 person.xsd 和实例文档 person.xml。 架构包含类型 Person,该类型具有 nameheight 元素的元素声明。 height 元素声明包括值为 truenillable 属性。 它还包含一个映射 person 元素的元素声明,person 元素的 nameheight 这两个子元素映射到 com:People 命名空间。 height 元素包含一个 xsi:nil 特性,该特性值为 true 时,表示该元素不应包含内容。

<xs:schema xmlns:xs= "http://www.w3.org/2001/XMLSchema"
   targetNamespace="urn:contoso-com:People"
   xmlns:ns="urn:contoso-com:People">

   <xs:complexType name="Person">
      <xs:sequence>
         <xs:element name= "name" type="xs:string"/>
         <xs:element name= "height" type="xs:double" nillable="true" />
      </xs:sequence>
   </xs:complexType>

   <xs:element name="Person" type="ns:Person" />
</xs:schema>
<p:person xmlns:p="urn:contoso-com:People">
   <name>John</name>
   <height xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
      xsi:nil="true" />
</p:person>

请参见

参考

XML 架构 (XSD) 参考

XML 架构元素

XML 架构实例特性