Re: Question about checking dependencies between fields in xml document via xsd
Ионов Дмитрий Петрович <[email protected]>
| Newsgroups | gmane.text.xml.schema.devel |
|---|---|
| Message-ID | <[email protected]> |
>On 11/05/2011 17:25, Ионов Дмитрий Петрович wrote: >> >> Hello. >> >> During a few days I can't solve one problem. >> >> There are two groups of fields in the xml file >> >> first >> >> <field1></field1> >> <field2></field2> >> <field3></field3> >> >> second >> >> <field4></field4> >> <field5></field5> >> >> All fields in the same level of document. >> >> I need to check filled/presents or not at least one of these groups. >> >> >It's not entirely clear to me what your requirement is. Perhaps you want > ><xs:choice minOccurs="1" maxOccurs="unbounded"> ><xs:sequence> ><xs:element name="f1"/> ><xs:element name="f2"/> ><xs:element name="f3"/> ></xs:sequence> ><xs:sequence> ><xs:element name="f4"/> ><xs:element name="f5"/> ></xs:sequence> ></xs:choice> Unfortunately no :-( I have an xml document like as: <Document DOC_ID="1" version="1"> <doc_HEADER> <header_field1>aaa</header_field1> <header_field2>bbb</header_field2> <header_field3>ccc</header_field3> </doc_HEADER> <doc_body> <some_field1>sf1</some_field1> <some_field2>sf2</some_field2> <some_field3>sf3</some_field3> <items> <item> <item_c>item_</item_c> <item_q>1</item_q> </item> </items> <field1></field1> <field2></field2> <field3></field3> <field4></field4> <field5></field5> </doc_body> </Document> And doc_body can be in 3 variants 1. see upper (in xml document sample) 2. <doc_body> <some_field1>sf1</some_field1> <some_field2>sf2</some_field2> <some_field3>sf3</some_field3> <items> <item> <item_c>item_</item_c> <item_q>1</item_q> </item> </items> <field1></field1> <field2></field2> <field3></field3> </doc_body> 3. <doc_body> <some_field1>sf1</some_field1> <some_field2>sf2</some_field2> <some_field3>sf3</some_field3> <items> <item> <item_c>item_</item_c> <item_q>1</item_q> </item> </items> <field4></field4> <field5></field5> </doc_body> Variant <doc_body> <!- some firlds --> <field2></field2> <field3></field3> <field5></field5> </doc_body> Or something like is wrong. And now XSD sees so <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:include schemaLocation="common_types.xsd"/> <xsd:element name="Document"> <xsd:complexType> <xsd:all> <xsd:element name="doc_HEADER" type="type_doc_HEADER"/> <xsd:element name="ERRORS" type="type_ERRORS" minOccurs="0"/> <xsd:element name="doc_body" type="type_doc_body"/> </xsd:all> <xsd:attribute name="DOC_ID" type="xsd:int"/> <xsd:attribute name="version" type="xsd:int"/> </xsd:complexType> </xsd:element> <xsd:complexType name=" type_doc_body"> <xsd:all> <xsd:element name=" some_field1" minOccurs="0"/> <xsd:element name=" some_field2" minOccurs="0"/> <xsd:element name=" some_field3" minOccurs="0"/> <xsd:element name="field1"/> <xsd:element name="field2"/> <xsd:element name="field3"/> <xsd:element name="field4"/> <xsd:element name="field5"/> </xsd:all> </xsd:complexType> </xsd:schema> How I can change XSD for check all variants of doc_body ?