471,316 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 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 5982
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nate | last post: by
4 posts views Thread by Abhijit Thatte | last post: by
7 posts views Thread by ray | last post: by
2 posts views Thread by craig.wagner | last post: by
5 posts views Thread by hello | last post: by
reply views Thread by rosydwin | last post: by

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.