473,486 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSD.exe handling of mixed content types in generate classes?

I'm trying to generate class definitions from an XSD that contains something
like:

<xs:complexType name="foo" mixed="true">
<xs:choice minOccurs = "0" maxOccurs="unbounded">
<xs:element name = "bar" type = "something"/>
...
<xs:element name = "baz" type = "somethingelse"/>
</xs:choice>
</xs:complexType>

The C# code generated by XSD.exe creates a class that has an array of
objects to allow for an arbitrary number of elements (reflecting the
maxOccurs="unbounded"), but doesn't appear to allow for possible text chunks
occurring between the bar and/or baz elements. When I actually deserialize
into the generated class structure from an XML containing such text I get no
errors or complaints, but the resulting objects have arrays of length 1
containing just the bar/baz element and nothing reflecting the text that is
in the XML file.

Based on a google search I found an article that implies XSD.exe doesn't
really handle mixed content well, but the example used a sequence rather
than a choice compositor. It appears from my experience that, in the case of
"choice" it doesn't handle it at all!

Anyway, I'm basing all this on the "old" version of .Net and am wondering if
the VS 2003 version of XSD.exe does any better with mixed content schema.
Also, is it possible for me to handle these sorts of cases by providing some
custom serialize/deserialize code?

Thanks in advance,
Bill
Nov 11 '05 #1
15 5370
Hello Bill,

What is the "text chunks" occurring between the bar and/or baz? Can you
give me a sample? Thanks.
Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."

Nov 11 '05 #2
[I posted this reply some hours ago, but since it dosen't appear to have
made it am possibly duplicating it...]

Just text, as you would expect in a mixed = "true" content model. Think of
the XSD you'd use to model XHTML text with embedded <p> elements, etc.

Bill
"MSFT" <lu******@online.microsoft.com> wrote in message
news:7l**************@cpmsftngxa06.phx.gbl...
Hello Bill,

What is the "text chunks" occurring between the bar and/or baz? Can you
give me a sample? Thanks.
Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."

Nov 11 '05 #3
I think the problem should be related to the namespace for the "text
chunks". Without a known namespace, xsd.exe will generate an error. I
believe following code should work:

<xs:element name = "bar" type = "xs:int"/>
<xs:element name = "bat" type = "xs:int"/>
<xs:element name = "baz" type = "xs:int"/>

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #4
Luke-
I'm afraid I didn't make this clear enough as you haven't addressed the
problem. Consider the XSD fragment:

<xs:complexType name="foo" mixed="true">
<xs:choice minOccurs = "0" maxOccurs="unbounded">
<xs:element name = "bar" type = "something"/>
...
<xs:element name = "baz" type = "somethingelse"/>
</xs:choice>
</xs:complexType>

In the above example let's assume that "something" and "somethingelse" are
themselves defined by xs:complexType elements within the same XSD, but their
particular structure is unimportant. What IS important is the 'mixed =
"true"' attribute in the complexType named foo. Assuming we have an element
fooelt defined to be of type "foo", we expect to see XML of the form...

<fooelt>
now is <something/> the time <somethingelse/> for <somethingelse/> all
<something/> good programmers
</fooelt>

The code generated by XSD.exe handles the <something> and <somethingelse>
elements OK, but makes no allowance AT ALL for the text. I hope this is a
better explanation of the problem.

Thanks,
Bill

"MSFT" <lu******@online.microsoft.com> wrote in message
news:r8**************@cpmsftngxa06.phx.gbl...
I think the problem should be related to the namespace for the "text
chunks". Without a known namespace, xsd.exe will generate an error. I
believe following code should work:

<xs:element name = "bar" type = "xs:int"/>
<xs:element name = "bat" type = "xs:int"/>
<xs:element name = "baz" type = "xs:int"/>

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #5
Luke:

From the .Net Framework General Reference, searching by complexType, see
the description of the "mixed" attribute of the complexType element where it
says:

"mixed
An indicator of whether character data is allowed to appear between the
child elements of this complex type. The default is false. "
So, according to this, text is allowed between the elements derived from the
xs:choice compositor. Also, by way of empirical support, I am able to
validate my XML (which contains the embedded text) against the XSD that uses
the xs:choice within the complexType with mixed = "true". My problem isn't
that the XSD validator is rejecting the XML, it's that XSD.exe is not
generating code to handle such text.

Regards,

Bill

"MSFT" <lu******@online.microsoft.com> wrote in message
news:7X*************@cpmsftngxa06.phx.gbl...
Hi Bill,

From the definition of "xs:choice" in .NET framework, its contents should
be these:

annotation, any, choice, element, group, sequence

If you add some text in its contents, the syntax may not be correct.

For more in information on "xs:choice" you may refer to:

http://msdn.microsoft.com/library/de...us/cpgenref/ht ml/xsdrefchoiceelement.asp

If I misunderstood the problem, please feel free to let me know.

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #6
Hi Bill

"mixed=true" means you can use charactors in the XML file, not XSD file (in
xs:choice). XSD.exe will open the XSD file, so that i can't recognize the
text.

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #7
Luke-
That's EXACTLY WHAT I'M TALKING ABOUT! I'm specifying an XSD that
describes a structure using a xs:choice element within an xs:complexType
with mixed="true". Thus, given an XML file that has text "between the child
elements" of an element of that complexType, it should (and does) validate
just fine. The object model code generated by XSD.exe however does NOT allow
for the text in the XML file.

Is that any clearer?

Bill

"MSFT" <lu******@online.microsoft.com> wrote in message
news:JK****************@cpmsftngxa06.phx.gbl...
Hi Bill

"mixed=true" means you can use charactors in the XML file, not XSD file (in xs:choice). XSD.exe will open the XSD file, so that i can't recognize the
text.

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #8
Hi Bill,

You may add an element with String type:

<xs:choice minOccurs = "0" maxOccurs="unbounded">
<xs:element name = "bar" type = "xs:int"/>
<xs:element name="anyString" type="xs:string" />
<xs:element name = "baz" type = "xs:int"/>
</xs:choice>

This will make XSD.exe have a sense to the charactors in the XML file?

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #9
Luke-
Thanks for the suggestion; however in this case the text needs to appear
as text *between* the children of the complexType rather than *within
elements* that are children of the complex type. My original question
acknowledged that original XSD.EXE cannot handle this case (you agree, don't
you?) -- but I was wondering whether the new one (assuming there's a new
version with VS 2003) provides any relief.

The bottom line is that there are perfectly valid XSD files for which
XSD.exe generates faulty runtime code. This is "documented" if you're good
with google, but there isn't (or I couldn't find) any up front MS
documentation on this. For instance, it'd be nice if XSD.exe provided an
error message or at least an embedded comment in the generated code to warn
the user that there's a problem when it encounters a case it can't handle.

Regards,
Bill

"MSFT" <lu******@online.microsoft.com> wrote in message
news:CM**************@cpmsftngxa06.phx.gbl...
Hi Bill,

You may add an element with String type:

<xs:choice minOccurs = "0" maxOccurs="unbounded">
<xs:element name = "bar" type = "xs:int"/>
<xs:element name="anyString" type="xs:string" />
<xs:element name = "baz" type = "xs:int"/>
</xs:choice>

This will make XSD.exe have a sense to the charactors in the XML file?

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #10
Hi Bill,

I test XSD.exe in VS.NET 2003 and I got similar result. XSD.exe ignores the
"mixed=true". There is a related KB article you may refer to it:

PRB: XmlElementAttribute Is Missing for the Generated Class Members While
Using Xsd.exe
http://support.microsoft.com/default...;EN-US;Q816222
Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #11
Luke,
Thanks, but I don't see that this article has anything to do with XSD
ignoring "mixed = true" in a complexType element.

Bill
"MSFT" <lu******@online.microsoft.com> wrote in message
news:BU**************@cpmsftngxa06.phx.gbl...
Hi Bill,

I test XSD.exe in VS.NET 2003 and I got similar result. XSD.exe ignores the "mixed=true". There is a related KB article you may refer to it:

PRB: XmlElementAttribute Is Missing for the Generated Class Members While
Using Xsd.exe
http://support.microsoft.com/default...;EN-US;Q816222
Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #12
Hi Bill,

The mixed attribute indicates whether character data is permitted to appear
between the child elements of the complexType class. The default value of
mixed is false. However, when you add anyAttribute to a complex type
element that has mixed set to true, the mixed attribute is ignored.

This behavior is by design.

To work around this problem, do not use anyAttribute inside mixed
attributes when you want to enter character data between child elements.

For more information about XML Schema design patterns, visit the following
Microsoft Developer Network (MSDN) Web site:

http://msdn.microsoft.com/library/de....asp?contentid
=28000438

If you have any Qs, please reply to this post.

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 11 '05 #13
Parker
Thanks for pointing this out; however I wasn't using anyAttribute at all.
I was complaining that XSD.exe didn't properly handle mixed = "true" when
generating code.

Bill
"Parker Zhang [MSFT]" <pa******@online.microsoft.com> wrote in message
news:kw**************@cpmsftngxa06.phx.gbl...
Hi Bill,

The mixed attribute indicates whether character data is permitted to appear between the child elements of the complexType class. The default value of
mixed is false. However, when you add anyAttribute to a complex type
element that has mixed set to true, the mixed attribute is ignored.

This behavior is by design.

To work around this problem, do not use anyAttribute inside mixed
attributes when you want to enter character data between child elements.

For more information about XML Schema design patterns, visit the following
Microsoft Developer Network (MSDN) Web site:

http://msdn.microsoft.com/library/de....asp?contentid =28000438

If you have any Qs, please reply to this post.

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 11 '05 #14
Parker-
Out of curiosity, when you say "the mixed attribute is ignored", are you
saying that a validator ignores the mixed attribute or are you saying
XSD.exe ignores it? Although I think this has nothing to do with my original
post, I'm curious about this (and why it might be so).

Thanks,
Bill

"Parker Zhang [MSFT]" <pa******@online.microsoft.com> wrote in message
news:kw**************@cpmsftngxa06.phx.gbl...
Hi Bill,

The mixed attribute indicates whether character data is permitted to appear between the child elements of the complexType class. The default value of
mixed is false. However, when you add anyAttribute to a complex type
element that has mixed set to true, the mixed attribute is ignored.

This behavior is by design.

To work around this problem, do not use anyAttribute inside mixed
attributes when you want to enter character data between child elements.

For more information about XML Schema design patterns, visit the following
Microsoft Developer Network (MSDN) Web site:

http://msdn.microsoft.com/library/de....asp?contentid =28000438

If you have any Qs, please reply to this post.

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 11 '05 #15
Hi Bill,

A KB article on "mixed = true" will be public soon. I think it may address
this issue more exactly. Anyway, the root cause for the problem is same
with Q816222.

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #16

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

Similar topics

12
3170
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a...
0
2286
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress...
7
5961
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
9
2565
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
12
2760
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
9
2925
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected...
2
1584
by: bearophileHUGS | last post by:
Notes: - This email is about Mark Dufour's Shed Skin (SS) (http://shed-skin.blogspot.com), but the errors/ingenuousness it contains are mine. My experience with C++ is limited still. - The...
1
2196
by: Colin Desmond | last post by:
I have a dll assembly compiler with the /clr flag as it contains ref classes and traditional style C++ classes. I want to write unit tests for the ref classes in that assembly. VS2005 allows me...
8
2292
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
0
7099
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
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
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
7319
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...
0
5430
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,...
1
4864
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...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.