开发者

Do i have to use namespace to match xml documents?

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 &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 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>
        &开发者_StackOverflowlt;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...


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜