472,969 Members | 2,228 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XSD and xs:union?

It seems that the XSD tool supplied with VS2005 does not handle
"xs:union". Am I doing something wrong? Is there a work-around?

Here is a simple sample file:
--------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ELDataSet">
<xs:complexType>
<xs:sequence>
<xs:element name="TestElement" type="SpecialType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="SpecialType">
<xs:union memberTypes="SimpleInts Unknowns" />
</xs:simpleType>

<xs:simpleType name="SimpleInts">
<xs:restriction base="xs:integer">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
<xs:enumeration value="5" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="Unknowns">
<xs:restriction base="xs:integer">
<xs:enumeration value="0" />
<xs:enumeration value="-1" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
--------------------------------------------------

Running the XSD utility on this generates code that simply defines
"TestElement" as a string (as opposed to an integer), and has none of
the enumeration values at all.

Thoughts?

Thanks!
Brad.
May 22 '07 #1
4 6123
KJ
Check this:

http://msdn2.microsoft.com/en-us/library/bc57azyw.aspx

"Bradley Plett" <pl****@newsgroup.nospamwrote in message
news:ub********************************@4ax.com...
It seems that the XSD tool supplied with VS2005 does not handle
"xs:union". Am I doing something wrong? Is there a work-around?

Here is a simple sample file:
--------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ELDataSet">
<xs:complexType>
<xs:sequence>
<xs:element name="TestElement" type="SpecialType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="SpecialType">
<xs:union memberTypes="SimpleInts Unknowns" />
</xs:simpleType>

<xs:simpleType name="SimpleInts">
<xs:restriction base="xs:integer">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
<xs:enumeration value="5" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="Unknowns">
<xs:restriction base="xs:integer">
<xs:enumeration value="0" />
<xs:enumeration value="-1" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
--------------------------------------------------

Running the XSD utility on this generates code that simply defines
"TestElement" as a string (as opposed to an integer), and has none of
the enumeration values at all.

Thoughts?

Thanks!
Brad.

May 22 '07 #2
Well, that really sucks! :-(

But thanks a lot for your quick reponse. :-)

Brad.

On Tue, 22 May 2007 17:42:05 -0400, "KJ" <n_**********@Mail.com>
wrote:
>Check this:

http://msdn2.microsoft.com/en-us/library/bc57azyw.aspx

"Bradley Plett" <pl****@newsgroup.nospamwrote in message
news:ub********************************@4ax.com.. .
>It seems that the XSD tool supplied with VS2005 does not handle
"xs:union". Am I doing something wrong? Is there a work-around?

Here is a simple sample file:
--------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="ELDataSet">
<xs:complexType>
<xs:sequence>
<xs:element name="TestElement" type="SpecialType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="SpecialType">
<xs:union memberTypes="SimpleInts Unknowns" />
</xs:simpleType>

<xs:simpleType name="SimpleInts">
<xs:restriction base="xs:integer">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
<xs:enumeration value="5" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="Unknowns">
<xs:restriction base="xs:integer">
<xs:enumeration value="0" />
<xs:enumeration value="-1" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
--------------------------------------------------

Running the XSD utility on this generates code that simply defines
"TestElement" as a string (as opposed to an integer), and has none of
the enumeration values at all.

Thoughts?

Thanks!
Brad.
May 22 '07 #3
Hi Brad,
Thanks for KJ's quickly reply.

I'm afraid there are two issue in your XSD file.

1) Actually, XSD.exe doesn't support xs:union.

http://msdn2.microsoft.com/en-us/library/bc57azyw.aspx
[Union Element Binding Support ]
When Xsd.exe encounters a simple type defined by union, it will ignore the
<simpleTypedefinition and uses the built-in string data type in its place.

To resolve this issue, you may create a union SimpeType manually in your
xsd file.
<xs:simpleType ...>
<xs:restriction ...>
<xs:enumeration value="1" />
...
<xs:enumeration value="0" />
<xs:enumeration value="-1" />
</xs:restriction>
</xs:simpleType>
2) Only when the <enumerationfacet is applied to string-based types like
xsd:string does the Xsd.exe translate it into a .NET Framework enum
definition
http;//msdn2.microsoft.com/en-us/library/z2w0sxhf.aspx
[Enumeration Element Binding Support]

This means the "SimpleInts" in your xsd file will be translated as "string"
type rather than "int" type.
<xs:simpleType name="SimpleInts">
<xs:restriction base="xs:int">
<xs:enumeration value="1" />
...
</xs:restriction>

Otherwise, you may set base to "xs:int" and delete enumeration from your
xsd file.
<xs:simpleType name="SimpleInts">
<xs:restriction base="xs:int">
</xs:restriction>

Hope this helps. Please let me know if you have anything unclear. I'm glad
to assit you.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 23 '07 #4
Hello Brad,

This is Wen Yuan again. I just want to check if there is anything we can
help with.
If you still have anything unclear or any more concern, please let me know
and I'm glad to assist you.

Have a nice weekend. Thanks.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 25 '07 #5

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

Similar topics

4
by: Nate | last post by:
Hello, I'd like to somehow put minIncl and maxIncl around the data I am sending from my producer. One of the requirements is to allow the producer to send an invalid number to the consumer. ...
2
by: Adam Retter | last post by:
I would like to have an element defined in my XML Schema, that can hold either an xs:string or xs:int value. Is this possible? e.g. something like - <xs:element name="service">...
4
by: Abhijit Thatte | last post by:
Hi, When I try to compile xsd file with xsd.exe that comes with Visual Studio.NET 2003 with following command line: xsd /d /l:"Microsoft.MCpp.MCppCodeProvider, MCppCodeDomProvider,...
7
by: ray | last post by:
My xsd has the following element: <xs:element name="Company" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1" /> <xs:maxLength value="5" />...
2
by: craig.wagner | last post by:
I have an element in my schema defined as follows: <xs:element name="BillingDate" type="xs:dateTime" nillable="true" minOccurs="0"/> I use the schema to validate incoming documents using an...
5
by: hello | last post by:
How can I define the schema so that myage element has to be double or null? <xs:simpleType name="myage"> <xs:restriction base="xs:double"> <xs:enumeration value="null"/> </xs:restriction>...
1
by: stran | last post by:
I'm trying to create a simple type that holds two different types. The first is IDREF and the second is an enumeration of string. When I generate a sample xml, I can enter any ID previously stated in...
4
by: voorth | last post by:
I was wondering if it is possible to define an restricted attribute such that the following forms are both valid: <myElement value="hi"/<!-- value should be "hi" or "lo" --> <myElement...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.