模式定义中的和之间的区别?

时间:2023-02-12 22:29:26

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.

我正在使用xsd:都是复杂类型。当我在验证时漏掉任何强制元素时,它将显示所有的元素。它将不会显示被遗漏的元素。

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

但是如果我使用xsd:sequence,我可以得到确切的被忽略的元素。

Is there any difference between these two?

这两者之间有什么区别吗?

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

序列:XML元素的顺序必须相同。

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

但是xsd:all: XML元素可以是任意顺序。

5 个解决方案

#1


89  

<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 a XML from this xsd then, it will something like this:

如果您从这个xsd创建一个XML,那么它将如下所示:

<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 a XML file from this xsd then it will something like this :

如果您从这个xsd创建一个XML文件,那么它将如下所示:

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

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

更多关于xsd的信息:更多关于xsd的信息:序列。

Hope i answered your quetion.

希望我回答了你的问题。

#2


16  

Difference:

的区别:

  • xsd:all - "child elements can appear in any order and each child element can occur zero or one time" (ie, maxOccurs can be 0 or 1)
  • 所有的“子元素可以以任何顺序出现,每个子元素可以出现0或1次”(例如,maxOccurs可以是0或1)
  • xsd:sequence - "child elements must appear in a sequence. Each child element can occur from 0 to any number of times" (ie, maxOccurs can be 0 or any number or 'unbounded')
  • 序列——“子元素必须以序列的形式出现。每个子元素都可以出现在0到任意次数之间(例如,maxOccurs可以是0或任何数字或'unbounded')

From the W3Schools tutorials here and here.

从W3Schools教程这里和这里。

#3


2  

All Indicator

所有的指标

The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:

指示符指定子元素可以以任何顺序出现,并且每个子元素必须只发生一次:

Sequence Indicator

序指示器

The <sequence> indicator specifies that the child elements must appear in a specific order:

指示灯指定子元素必须以特定的顺序出现:

reference link

参考链接

#4


0  

when we use under tag, it indicates all the elements that are declared in that complexType MUST appear in same order in XML document. otherwise, you will get an error. for there is no need to specify elements in proper order.

当我们使用under tag时,它指示在该complexType中声明的所有元素在XML文档中必须以相同的顺序出现。否则,您将得到一个错误。因为没有必要以适当的顺序指定元素。

#5


0  

The schema merely defines what constitutes a compliant document.

模式仅仅定义了什么构成了兼容的文档。

How non-compliance is reported is entirely up to the validator. There is nothing stopping a validator from reporting exactly which fields are missing, but apparently the one you use does not in this case.

如何报告不遵从性完全取决于验证器。没有任何东西可以阻止验证器准确地报告哪些字段丢失了,但是很明显,在这种情况下,您使用的字段并不存在。

Whether that is a bug or by design you would have to discuss with the provider of the validator.

无论这是一个bug还是设计上的问题,您都必须与验证器的提供者进行讨论。

#1


89  

<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 a XML from this xsd then, it will something like this:

如果您从这个xsd创建一个XML,那么它将如下所示:

<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 a XML file from this xsd then it will something like this :

如果您从这个xsd创建一个XML文件,那么它将如下所示:

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

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

更多关于xsd的信息:更多关于xsd的信息:序列。

Hope i answered your quetion.

希望我回答了你的问题。

#2


16  

Difference:

的区别:

  • xsd:all - "child elements can appear in any order and each child element can occur zero or one time" (ie, maxOccurs can be 0 or 1)
  • 所有的“子元素可以以任何顺序出现,每个子元素可以出现0或1次”(例如,maxOccurs可以是0或1)
  • xsd:sequence - "child elements must appear in a sequence. Each child element can occur from 0 to any number of times" (ie, maxOccurs can be 0 or any number or 'unbounded')
  • 序列——“子元素必须以序列的形式出现。每个子元素都可以出现在0到任意次数之间(例如,maxOccurs可以是0或任何数字或'unbounded')

From the W3Schools tutorials here and here.

从W3Schools教程这里和这里。

#3


2  

All Indicator

所有的指标

The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:

指示符指定子元素可以以任何顺序出现,并且每个子元素必须只发生一次:

Sequence Indicator

序指示器

The <sequence> indicator specifies that the child elements must appear in a specific order:

指示灯指定子元素必须以特定的顺序出现:

reference link

参考链接

#4


0  

when we use under tag, it indicates all the elements that are declared in that complexType MUST appear in same order in XML document. otherwise, you will get an error. for there is no need to specify elements in proper order.

当我们使用under tag时,它指示在该complexType中声明的所有元素在XML文档中必须以相同的顺序出现。否则,您将得到一个错误。因为没有必要以适当的顺序指定元素。

#5


0  

The schema merely defines what constitutes a compliant document.

模式仅仅定义了什么构成了兼容的文档。

How non-compliance is reported is entirely up to the validator. There is nothing stopping a validator from reporting exactly which fields are missing, but apparently the one you use does not in this case.

如何报告不遵从性完全取决于验证器。没有任何东西可以阻止验证器准确地报告哪些字段丢失了,但是很明显,在这种情况下,您使用的字段并不存在。

Whether that is a bug or by design you would have to discuss with the provider of the validator.

无论这是一个bug还是设计上的问题,您都必须与验证器的提供者进行讨论。