473,402 Members | 2,055 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,402 software developers and data experts.

XML Schema - Choice usage

Hi, Everyone!

I'd need a little help. I understand this is not valid, but is there
an (easy) way to make it valid?

<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence<!-- static -->
<xs:element name="type" type="xs:positiveInteger" fixed="28251"/>
<xs:element name="h_align" type="h_align_Type"/>
<xs:element name="v_align" type="v_align_Type"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence<!-- check -->
<xs:element name="type" type="xs:positiveInteger" fixed="28252"/>
<xs:element name="is_checked" type="xs:boolean"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

Thank you very much!
Chris

Apr 5 '07 #1
2 2136
On 5 Apr, 08:49, "puffy" <puffy.ch...@gmail.comwrote:
Hi, Everyone!

I'd need a little help. I understand this is not valid, but is there
an (easy) way to make it valid?

<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence<!-- static -->
<xs:element name="type" type="xs:positiveInteger" fixed="28251"/>
<xs:element name="h_align" type="h_align_Type"/>
<xs:element name="v_align" type="v_align_Type"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence<!-- check -->
<xs:element name="type" type="xs:positiveInteger" fixed="28252"/>
<xs:element name="is_checked" type="xs:boolean"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

Thank you very much!
Chris
I don't think schema currently offers any great solutions to this.
One option might be to do something like:

<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence<!-- static -->
<xs:element name="type28251"
type="empty"/>
<xs:element name="h_align"
type="h_align_Type"/>
<xs:element name="v_align"
type="v_align_Type"/>
<xs:element name="text"
type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence<!-- check -->
<xs:element name="type28252"
type="empty"/>
<xs:element name="is_checked"
type="xs:boolean"/>
<xs:element name="text"
type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

<xs:complexType name="empty"/>

Even I don't think that's pretty though!

Another option might be to use xsi:type in some way, and define a
number of restrictions or extensions for the various types.

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================

Apr 5 '07 #2
Hi,

"puffy" <pu*********@gmail.comwrites:
<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence<!-- static -->
<xs:element name="type" type="xs:positiveInteger" fixed="28251"/>
<xs:element name="h_align" type="h_align_Type"/>
<xs:element name="v_align" type="v_align_Type"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence<!-- check -->
<xs:element name="type" type="xs:positiveInteger" fixed="28252"/>
<xs:element name="is_checked" type="xs:boolean"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>
You need to make the first element in the two sequences differ
so the schema processor can figure out which arm of the choice
it is parsing just by looking at the first element. So one way
would be to place the 'type' element at the end. Or make it an
attribute. I like the attribute option better since it has the
nice notion of storing "meta information" in attributes and
"data" in elements.
hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding
Apr 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
0
by: CJ | last post by:
I started with this schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="response"> <xs:complexType> <xs:sequence> <xs:element...
3
by: Kimmo J?rvikangas | last post by:
Dear XML (Schema) experts, As an example I have the following schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"...
2
by: BillD | last post by:
I'm trying to derive a schema from a base schema. I want to redefine a "group" from the base schema in my derived schema in order to add more options to the "choice" aggregate (see schema1.xsd...
0
by: Deep Purple | last post by:
I started with the following error... ------------------------------------------------------- An error occured while loading the schema with TargetNamespace 'http://www.w3.org/2001/XMLSchema'...
5
by: j.tremlett | last post by:
Hi, I have read various articles on this and I have had a few suggestions but would like to know which is correct. I have an XML file with the element <root> Within <root> I can have a...
1
by: Chris Lieb | last post by:
I am new to XML Schema and am running into a bit of a snag. I have defined an XML-based scripting language for an updater program that I am working on. I would like to make a schema for this...
4
by: cmay | last post by:
I am beginning to wonder if it is not possible to get this working. I am trying to do: <root> <a/> <b/> <c/> </root>
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.