all groups > dotnet xml > may 2007 >
You're in the

dotnet xml

group:

XSD and xs:union?


XSD and xs:union? Bradley Plett
5/22/2007 1:43:30 PM
dotnet xml:
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!
Re: XSD and xs:union? Bradley Plett
5/22/2007 4:12:49 PM
Well, that really sucks! :-(

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

Brad.

On Tue, 22 May 2007 17:42:05 -0400, "KJ" <n_o_s_p_a__M@Mail.com>
[quoted text, click to view]
Re: XSD and xs:union? KJ
5/22/2007 5:42:05 PM
Check this:

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

[quoted text, click to view]

Re: XSD and xs:union? v-wywang NO[at]SPAM online.microsoft.com
5/23/2007 12:00:00 AM
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
<simpleType> definition 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 <enumeration> facet 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: XSD and xs:union? v-wywang NO[at]SPAM online.microsoft.com
5/25/2007 12:00:00 AM
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.
AddThis Social Bookmark Button