Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
943 views
in Technique[技术] by (71.8m points)

xml - Difference between <xsd:all> and <xsd:sequence> in schema definition?

I am using xsd:all in a complex type. When I miss any mandatory elements while validating it will show all the elements. It will not display the exact missed element.

But if I am use xsd:sequence I can get the exact missed element.

Is there any difference between these two?

xsd:sequence: XML element must be in same order.

But xsd:all: XML element may be any order.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

<xsd:all> specifies that the child elements can appear in any order.

<xsd:sequence> specifies child elements can only appear in the order mentioned.

Example for Sequence:

<xs:element name="compElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="ele1" type="xs:string"/>
      <xs:element name="ele2" type="xs:string"/>
      <xs:element name="ele3" type="xs:string"/>
      <xs:element name="ele4" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

If you create an XML from this xsd then, it will look something like this:

<compElement>
  <ele1>First</ele1>
  <ele2>Second</ele2>
  <ele3>Third</ele3>
  <ele4>Fourth</ele4>
</compElement>

Example for all:

<xs:element name="compElement">
  <xs:complexType>
    <xs:all>
      <xs:element name="ele1" type="xs:string"/>
      <xs:element name="ele2" type="xs:string"/>
      <xs:element name="ele3" type="xs:string"/>
      <xs:element name="ele4" type="xs:string"/>
    </xs:all>
  </xs:complexType>
</xs:element>

If you create an XML file from this xsd then it could look something like this:

<compElement>
  <ele2>Second</ele2>
  <ele1>First</ele1>
  <ele4>Fourth</ele4>
  <ele3>Third</ele3>
</compElement>

More info on xsd:all
More Info on xsd:sequence

Hope I answered your question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...