开发者

How do I specify a list of required xml child elements that DONT need to be in sequence?

The following xml validates against the supplied xsd document. However when i start removing elements like from the xml it STILL validates!?

How do I write an xsd that forces the inclusion of elements?

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

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


If you use xs:all as opposed to xs:sequence, the elements may appear in any order. There are some additional restrictions - for example, elements can not be specified multiple times using all (I'm not sure if you intend that usage, your schema would currently allow that.)


Your targetNamespace in the xsd should match the namespace of the xml you are trying to validate, i.e.

<Video xmlns="http://tempuri.org/UploadXSD.xsd">
  <Title>
  </Title>
  <Description>
  </Description>
  <Contributor>
  </Contributor>
  <Subject>
  </Subject>
</Video>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜