如何匹配元素,但如果存在属性,则避免验证失败?

时间:2010-11-30 11:17:18

标签: xml xsd xml-validation

我有xml:

<video contenttype="asf" fileextension=".wmv" hascontent="no" lang="en-GB" length="1800" pid="3678738364972" sid="">
  <title>A vid with Pete</title>
  <description>Petes vid</description>
  <contributor>Pete</contributor>
  <subject>Cat 2</subject>
</video>

我想使用xsd架构验证视频元素是否存在,但我真的不在乎它具有什么属性(实际上我想忽略这些属性)。我所关心的只是存在的视频元素。是否可以使用xsd?

执行此操作

目前xsd是:

<?xml version="1.0" encoding="utf-8"?>

<xs:schema id="UploadXSD"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/UploadXSD.xsd"
    xmlns:mstns="http://tempuri.org/UploadXSD.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="video">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="description" type="xs:string"></xs:element>
        <xs:element name="contributor" type="xs:string"></xs:element>
        <xs:element name="subject" type="xs:string"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

1 个答案:

答案 0 :(得分:2)

是的,只需在序列后面的xs:anyAttribute元素中指定complexType:此处为a link