我必须使用命名空间来匹配 xml 文档吗?

发布于 2024-10-04 18:07:33 字数 4177 浏览 2 评论 0原文

尝试让 xsd 匹配两个文档时遇到了一些麻烦:

XML 文档 1:

<?xml version="1.0" encoding="UTF-8"?>
<video contenttype="asf" fileextension=".wmv" hascontent="no" lang="en-GB" length="1800" pid="3678738364972" sid="">
    <lastmodified timestamp="1282678200000">
        Tue, 24 Aug 2010 19:30:00 +0000
    </lastmodified>
    <links/>
    <keywords/>
    <slides/>
    <copyright>
        Copyright owned by original broadcaster
    </copyright>
    <title>
        Friends
    </title>
    <comment>
        The One Where the Monkey Gets Away: Rachel accidentally lets Ross's pet monkey escape, then learns that her former best friend is engaged to marry her ex-fiancé.  [AD,S]
    </comment>
    <author>
        E4
    </author>
    <email/>
    <captioning/>
    <extendeddata>
        <data name="keepOriginal">
            0
        </data>
        <data name="keepTranscoded">
            0
        </data>
        <data name="realStartTime">
            1282677909
        </data>
        <data name="scheduledStartTime">
            1282678200
        </data>
        <data name="broadcastLength">
            1800
        </data>
        <data name="broadcastChannel">
            E4
        </data>
        <data name="paddingUsed">
            300000
        </data>
        <data name="transcodingSpec">
            -b 2.35M -a 128k --debug  --primary-format mp4 --podcast &quot;-l 270 -b 600 -R 48 -B 64&quot; --keep-files true
        </data>
        <data name="transcoding">
            succeeded
        </data>
        <data name="transcodingProfile">
            -b 2.35M -a 128k --debug  --primary-format mp4 --podcast &quot;-l 270 -b 600 -R 48 -B 64&quot; --keep-files true
        </data>
        <data name="transcoderDetails">
            ver 1.58.2.1, 2010-08-24  21:31:33 up 5 days, 11:24,  0 users,  load average: 3.08, 3.38, 2.67, OS20031 212.70.69.26
        </data>
        <data name="originalFilename">
            /var/lib/etvd/mpegts/E4/Friends (24-Aug-2010 20.30).emcast
        </data>
        <data name="originalRecordingTime">
            created 2010-08-24 , last modified 2010-08-24 : recording lasted 0s
        </data>
        <data name="primaryFormat">
            mp4
        </data>
        <data name="doXml">
            True
        </data>
        <data name="doFiles">
            True
        </data>
    </extendeddata>
    <categories>
        <category name="em:podcast">
            mp4
        </category>
    </categories>
</video>

XML 文档 2:

<?xml version="1.0" encoding="UTF-8"?>
<video xmlns="UploadXSD">
  <title>
    A vid with Pete
  </title>
  <description>
  Petes vid
  </description>
  <contributor>
    Pete
  </contributor>
  <subject>
    Cat 2
  </subject>
</video>

建议的 XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
    targetNamespace="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>

是否可以使用 c# 来验证这两个 xml 文档而不使用命名空间?因为 XML 文档 1(上面)是由第三方系统创建的,并且无法生成名称空间...

过去几天问了一些关于 xml 的问题,感谢帮助,对此我很陌生...

Having a bit of trouble trying to get an xsd to match two documents:

XML Document 1:

<?xml version="1.0" encoding="UTF-8"?>
<video contenttype="asf" fileextension=".wmv" hascontent="no" lang="en-GB" length="1800" pid="3678738364972" sid="">
    <lastmodified timestamp="1282678200000">
        Tue, 24 Aug 2010 19:30:00 +0000
    </lastmodified>
    <links/>
    <keywords/>
    <slides/>
    <copyright>
        Copyright owned by original broadcaster
    </copyright>
    <title>
        Friends
    </title>
    <comment>
        The One Where the Monkey Gets Away: Rachel accidentally lets Ross's pet monkey escape, then learns that her former best friend is engaged to marry her ex-fiancé.  [AD,S]
    </comment>
    <author>
        E4
    </author>
    <email/>
    <captioning/>
    <extendeddata>
        <data name="keepOriginal">
            0
        </data>
        <data name="keepTranscoded">
            0
        </data>
        <data name="realStartTime">
            1282677909
        </data>
        <data name="scheduledStartTime">
            1282678200
        </data>
        <data name="broadcastLength">
            1800
        </data>
        <data name="broadcastChannel">
            E4
        </data>
        <data name="paddingUsed">
            300000
        </data>
        <data name="transcodingSpec">
            -b 2.35M -a 128k --debug  --primary-format mp4 --podcast "-l 270 -b 600 -R 48 -B 64" --keep-files true
        </data>
        <data name="transcoding">
            succeeded
        </data>
        <data name="transcodingProfile">
            -b 2.35M -a 128k --debug  --primary-format mp4 --podcast "-l 270 -b 600 -R 48 -B 64" --keep-files true
        </data>
        <data name="transcoderDetails">
            ver 1.58.2.1, 2010-08-24  21:31:33 up 5 days, 11:24,  0 users,  load average: 3.08, 3.38, 2.67, OS20031 212.70.69.26
        </data>
        <data name="originalFilename">
            /var/lib/etvd/mpegts/E4/Friends (24-Aug-2010 20.30).emcast
        </data>
        <data name="originalRecordingTime">
            created 2010-08-24 , last modified 2010-08-24 : recording lasted 0s
        </data>
        <data name="primaryFormat">
            mp4
        </data>
        <data name="doXml">
            True
        </data>
        <data name="doFiles">
            True
        </data>
    </extendeddata>
    <categories>
        <category name="em:podcast">
            mp4
        </category>
    </categories>
</video>

XML Document 2:

<?xml version="1.0" encoding="UTF-8"?>
<video xmlns="UploadXSD">
  <title>
    A vid with Pete
  </title>
  <description>
  Petes vid
  </description>
  <contributor>
    Pete
  </contributor>
  <subject>
    Cat 2
  </subject>
</video>

Proposed XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
    targetNamespace="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>

Is it possible to use c# to validate against both of the xml documents and NOT use a namespace? Because with the XML Document 1 (above) it is created by a third party system and it cannot generate the namespace...

Asked a few questions about xml in the last few days appreciate help am very new to this...

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

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

发布评论

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

评论(2

笨笨の傻瓜 2024-10-11 18:07:34

我相信你确实需要匹配命名空间。我曾经遇到过类似的问题,其中 XML 文档超出了我的控制范围(Adobe Smart Forms),我想根据我的 XSD 对其进行验证。

为此,我在验证之前清理 XML 文档,调整命名空间,并在本例中删除了 Adob​​e 添加的大量垃圾。抱歉,我没有任何关于我如何做到这一点的代码。

I believe you do need to match namespace. I once faced a similar issue, where the XML document was out of my control (Adobe Smart Forms), and I wanted to validate it against my XSD.

To do this I cleaned the XML document before I validated, adjusting the namespace, and in my case removing alot of garbage that Adobe added. Sorry I don't have any code with me on how I did it.

装迷糊 2024-10-11 18:07:34

据我所知,您不需要名称空间。我从未在任何 XSD 模式中使用过它。

以下是 Microsoft 关于该功能的文档:
http://msdn.microsoft.com/en-us /库/aa258639%28SQL.80%29.aspx

As far as I'm aware, you don't need a namespace. I've never used one in any of my XSD schemas.

Here's Microsoft's documentation on the feature:
http://msdn.microsoft.com/en-us/library/aa258639%28SQL.80%29.aspx

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