2

次の xml は、提供された xsd ドキュメントに対して検証します。ただし、xml からのような要素の削除を開始すると、まだ検証されます!?

要素を強制的に含める xsd を作成するにはどうすればよいですか?

<?xml version="1.0" encoding="UTF-8"?>
<Video>
  <Title>
  </Title>
  <Description>
  </Description>
  <Contributor>
  </Contributor>
  <Subject>
  </Subject>
</Video>

それから私はxsdを持っています:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
    targetNamespace="http://tempuri.org/UploadXSD.xsd"
    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" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Contributor" minOccurs="1" type="xs:string"></xs:element>
        <xs:element name="Subject" minOccurs="1" type="xs:string"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>
4

2 に答える 2

4

xs:allとは対照的にを使用するxs:sequenceと、要素は任意の順序で表示されます。追加の制限がいくつかあります。たとえば、要素を複数回指定することはできませんall(その使用法を意図しているかどうかはわかりませんが、現在のスキーマでは許可されています)。

于 2010-11-29T15:14:02.787 に答える
1

xsd の targetNamespace は、検証しようとしている xml の名前空間と一致する必要があります。

<Video xmlns="http://tempuri.org/UploadXSD.xsd">
  <Title>
  </Title>
  <Description>
  </Description>
  <Contributor>
  </Contributor>
  <Subject>
  </Subject>
</Video>
于 2010-11-29T15:29:31.627 に答える