473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

xsd: validating from a selection of groups

Hello,
What I'm trying to achieve is allow within one element either one set of elements or another. I thought I achieved this creating a choice element of either an element or a group and it parsef fine with my old version 4 of xml spy, but it turns out it is incorrect due to 'the group ref to "all" is not the root particle'

As an example, for the element 'data' I want to allow either one set of fields or another, as in:
Expand|Select|Wrap|Line Numbers
  1. <data>
  2.  <none />
  3. </data>
Or,

Expand|Select|Wrap|Line Numbers
  1. <data>
  2.  <field1 />
  3.  <field2 />
  4. </data>
The xsd I created that achieved this as follows, but it is invalid:

Expand|Select|Wrap|Line Numbers
  1. <xs:element name="data" type="formtype" />
  2.  
  3. <xs:group name="form">
  4.  <xs:all>
  5.   <xs:element name="field1" />
  6.   <xs:element name="field2" />
  7.  </xs:all>
  8. </xs:group>
  9.  
  10. <xs:complexType name="formtype">
  11.  <xs:choice>        
  12.   <xs:element name="none" />
  13.   <xs:group ref="form"/>
  14.  </xs:choice>
  15. </xs:complexType> 

The thing I really don't understand is if I change xs:all to xs:sequence then it is valid, yet the difference between the two that I know is simply sequence must all be there and in the right order, and all must all be there but in any order, and I need the elements to be any order.

Any help in fixing this would be appreciated :)

Neil.
Jan 28 '08 #1
2 1647
jkmyoung
2,057 Expert 2GB
The reason is that whenever you use an xs:all it has to be the outermost content of an element. Otherwise, it increases the complexity too much for parsers to handle.
You could change it to a sequence, putting all possible combinations, but if you have many elements in the sequence, it might be too much to list all combinations. eg with the 2 current ones:
Expand|Select|Wrap|Line Numbers
  1. <xs:element name="data" type="formtype"/>
  2. <xs:group name="form1">
  3.     <xs:sequence>
  4.         <xs:element name="field1"/>
  5.         <xs:element name="field2"/>
  6.     </xs:sequence>
  7. </xs:group>
  8. <xs:group name="form2">
  9.     <xs:sequence>
  10.         <xs:element name="field2"/>
  11.         <xs:element name="field1"/>
  12.     </xs:sequence>
  13. </xs:group>
  14. <xs:complexType name="formtype">
  15.     <xs:choice>
  16.         <xs:element name="none"/>
  17.         <xs:group ref="form1"/>
  18.         <xs:group ref="form2"/>
  19.     </xs:choice>
  20. </xs:complexType>
  21.  
The usage of <none/> as a marker element is non-standard.
Jan 28 '08 #2
ok thanks, not being allowed to a choice of groups of elements seems like a big omission (unordered). However I can't rearrange them as the code I posted was just a sample, my real xsd has a large amount of fields.

Given what you've said I'm simply going to change my schema to have two different types, e.g.

<data1>
<field1 />
<field2/>
</data1>

and,
<data2>
<none />
</data2>

As for the marker element, that was just me making it simpler, it isn't like that in the real xsd.
Jan 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Prashanth Ellina | last post by:
Hi, I need to write some data to an xml file. I have an XML Schema defined. I would like to use some mechanism of writing the data to the xml file and having exceptions thrown back to me when...
4
by: Group IIS | last post by:
Hi all, I am using ALTOVA XMLSpy. The start of my XML file looks like this: <?xml version="1.0" encoding="UTF-8" ?> <Submission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
1
by: davisjoseph | last post by:
Hi All, I'm using Xerces C++ 2.50 DOM version for Validating a valid XML againt the Schema(XSD) available; But it always shows an error in XSD I suppose; This is the error I'm getting using...
1
by: Raj | last post by:
Hi All, I am having three XML files. One called SimpleTypes.xsd from which ComplexTypes.xsd is constructed. Then, there is another file called InformationExchangeModel.xsd that uses types in...
6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
2
by: forbes | last post by:
Hi, I have a form that contains multiple groups of checkboxes that act like radio buttons (at the clients insistance). There is one text field that is required and 28 checkbox groups. Here an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.