English 中文(简体)
元素的XML架构顺序
原标题:XML Schema order of elements
  • 时间:2010-10-19 19:09:56
  •  标签:
  • xsd

在我的XSD中,我希望能够指定元素的顺序无关紧要。这就是我所拥有的:

<xs:element name="ADT_A08_231_GLO_DEF">
  <xs:complexType>
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="EVN_EventTypeSegment" type="xs:string" />
      <xs:element minOccurs="1" maxOccurs="1" name="PID_PatientIdentificationSegment" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="PD1_PatientAdditionalDemographicSegment" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

如何使EVN和PID元素在XML文件中随机出现(首先是EVN,然后是PID,或者第一个PID元素,然后是EVN元素)?

<EVN_EventTypeSegment>Test</EVN_EventTypeSegment>
<PID_PatientIdentificationSegment>PIDTest</PID_PatientIdentificationSegment>

或:

<PID_PatientIdentificationSegment>PIDTest</PID_PatientIdentificationSegment>
<EVN_EventTypeSegment>Test</EVN_EventTypeSegment>
问题回答

使用xs:all,而不是xs:sequence

将模式文档中的xs:sequence更改为xs:all。包含对元素A、B和C的引用(或声明)的全群是满足的,当且仅当A、B、和C以某种顺序存在。元素可以将minOccurs设置为0以使其成为可选元素(如PD1_PatientAdditionalDemographicSegment元素)。

在XSD 1.0中,所有组的子级必须具有<code>maxOccurs</code>的1,有些人认为这是令人不安的限制,但在您的情况下,这正是您想要的。在XSD 1.1中,该限制被取消。





相关问题
How to validate DataTable with XML Schema?

Does anyone know how to validate a DataTable against a particular DataTable XSD (Schema)? Which would be the best performance-optimized way of doing this? For example: <?xml version="1.0" ...

Deprecated XML validation code problem C#

I m trying to figure out how to correct his deprecated xml schema validation code. public static bool ValidateXml(string xmlFilename, string schemaFilename) { ⁞ //Forward stream reading ...

Getting an object representation of an .XSD file in Java

What is the easiest way to obtain a statically typed representation of an XML schema (.XSD) in Java? More specifically I want to be able to programatically traverse all defined simpleType:s and ...

xmlserializer validation

I m using XmlSerializer to deserialize Xml achives. But I found the class xsd.exe generated only offers capability to read the xml, but no validation. For example, if one node is missing in a document,...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签