473,394 Members | 1,717 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.

Need help with Schema design

Hello all,

I'm trying to design a schema from which I can generate a
typed dataset class. I'm having problems incorporating
choice and enumerations in the schema and getting the xml
results that I want. In the following example I want the
TopElement to contain either a Car element *or* a Truck
element, but not both. So I tried to use a Choice tag to
accomplish this. However, The Car element is of type
CarType which is a simpleType that contains an
enumeration. I used the enumeration so I could control the
valid values in the element.

When I generate a typed dataset using "xsd.exe /d", the
code creates a Car *and* a Truck element instead of a Car
*or* a Truck element.

So, the question is... Why is my schema not generating
the results that I want?

Here is a simplified example of what I want the resulting
xml to look like.
<?xml version="1.0" standalone="yes" ?>
- <SampleSchema
xmlns="http://tempuri.org/SampleSchema.xsd">
- <TopElement>
<Car>SportsCar</Car>
<Color>Blue</Color>
</TopElement>
</SampleSchema>

Here are the results that I'm getting
<?xml version="1.0" standalone="yes" ?>
- <SampleSchema
xmlns="http://tempuri.org/SampleSchema.xsd">
- <TopElement>
<Car>SportsCar</Car>
<Truck>RegularCab</Truck>
<Color>Blue</Color>
</TopElement>
</SampleSchema>

Here is the schema that I wrote:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="SampleSchema"
targetNamespace="http://tempuri.org/SampleSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/SampleSchema.xsd"
xmlns:mstns="http://tempuri.org/SampleSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="TopElement"
type="TopElementType" />

<xs:complexType name="TopElementType">
<xs:sequence>
<xs:choice id="MyChoice" maxOccurs="1">
<xs:element name="Car" type="CarType"
maxOccurs="1" />
<xs:element name="Truck" type="TruckType"
maxOccurs="1" />
</xs:choice>
<xs:element name="Color" type="xs:string"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>

<xs:simpleType name="CarType">
<xs:restriction base="xs:string">
<xs:enumeration
value="SportsCar" />
<xs:enumeration value="Sedan" />
<xs:enumeration value="Mini" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="TruckType">
<xs:restriction base="xs:string">
<xs:enumeration
value="RegularCab" />
<xs:enumeration value="SuperCab" />
<xs:enumeration value="LongBed" />
</xs:restriction>
</xs:simpleType>

</xs:schema>
Nov 11 '05 #1
1 1503
Jeff S wrote:
When I generate a typed dataset using "xsd.exe /d", the
code creates a Car *and* a Truck element instead of a Car
*or* a Truck element.

So, the question is... Why is my schema not generating
the results that I want?


Well, typed dataset provides access to values using usual strongly typed
technics - Car and Truck become just public properties of
TopLevelElementRow class. And in C# you cannot have optional properties
- if you want to be able to set and get property value obviously you
need a property in a class at compile time. That's why in generated code
you have three properites for all 3 possible elements.
And what for xs:choice - I'm not surem but looks like this logic is
omitted in generated class. You can easily add it yourself though.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

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

Similar topics

6
by: Patrick K. O'Brien | last post by:
I'm looking for a good schema to use as an example for an object database system. Something like a books/authors/publishers or teachers/students/courses kind of thing. There are plenty of...
5
by: Ralf Wahner | last post by:
Dear Masters of XML As I'm new to XML Schema I dare to ask a possibly recurring question: Given an element <elem> with two attributes @a and @b. The attributes are bound by the condition, that...
1
by: Val Melamed | last post by:
Hi all, These days I'm playing with schemas and SOM from MSXML. To learn it I used the excellent tutorial from Mr.Costello: http://www.xfront.com/xml-schema.html. while working through the...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
7
by: Philippe Poulard | last post by:
Hi, RefleX 0.1.3, a general-purpose XML Virtual Machine, is available here : http://reflex.gforge.inria.fr/ In this release, you'll find tutorials for mapping SQL to arbitrary complex XML...
3
by: stefan.rickfjord | last post by:
Hi, I am a newbie to programming using XML and I'm currently working on a side-project which will house some database information in a XML-file. I am writing a DTD to specify the XML-format,...
3
by: Eric Lilja | last post by:
Hello again, I'm having a new problem converting a dtd to an xml schema. This once is a little bit more complicated than in my previous question. The following file validates correctly: <?xml...
2
by: nirmalc | last post by:
Question 1: XYZ Company is a Car production company. It has four factories and many distribution outlets spread across the country. The company keeps online records of the sales of its cars. It also...
2
by: NITHYA LATHA | last post by:
XYZ Company is a Car production company. It has four factories and many distribution outlets spread across the country. The company keeps online records of the sales of its cars. It also creates...
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: 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: 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
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
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.