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

发布于 2024-10-04 23:55:05 字数 1263 浏览 0 评论 0原文

我有 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>

I have the 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>

And I want to validate the video element is present using an xsd schema but I really dont care what attributes it has (in fact I want to ignore the attributes). All I care about is the video element being present. Is it possible to do this with xsd?

Currently the xsd is:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衾梦 2024-10-11 23:55:05

是的,只需在 complexType 元素中的序列后面指定 xs:anyAttribute 即可:这里是 链接.

Yes, just specify xs:anyAttribute in your complexType element, after the sequence: here's a link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文