469,592 Members | 1,856 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Serializing classes generated by XSD.exe

Hi,
First, sorry for this long post, but i'd like to explain my problem in
detail...
i have generated some classes from my schema. Classes are generated
for the root (overall document), complexTypes with complexContents
(this is how my types in the xsd are defined), and elements defined as
complextypes that contain more than one unbounded child elements.

THe problem i am having is when i serialize Fragments of these classes
back to xml, the namespace does NOT appear for certain elements being
written. It seems that XSD.exe writes an XMLRootAttribute for the top
level root element, an XMLTypeAttribute for the complextypes with
complexContent, BUT writes an "XmlAttribute(AnonymousType=True)" for
the last case: classed based on elements defined as compexTypes that
contain more than one unbounded child elements. This means when this
class is serialized, no namespace is outputed. Further, if i manually
change the autogenerated code, the namespace is outputed for the child
elements defined in that class, but not for the toplevel element that
class represents.

Here's an example of what i a talking about

if i have a schema that looks like this:

<xsd:element name="Document">
<xsd:element name="title" type="xsd:string" type="xsd:anyType"/>
<xsd:element name="description" type="xsd:string"
type="xsd:string"/>
<xsd:element ref="tags" minOccurs="0" />

<xsd:element name="tags">
<xsd:complexType mixed="true">
<xsd:all>
<xsd:element ref="authors" minOccurs="0" />
<xsd:element ref="editors" minOccurs="0" />
...
</xsd:all>
</xsd:comlexType>
</xsd:element>

<xsd:element name="authors" />
<xsd:complexType>
<xsd:sequence>
<xsd:element name="author" type="AuthorType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="editors" />
<xsd:complexType>
<xsd:sequence>
<xsd:element name="editor" type="EditorType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name = "AuthorType">
<xsd:complexContent>
....
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name = "EditorType">
<xsd:complexContent>
....
</xsd:complexContent>
</xsd:complexType>

...
</xsd:element>

With the above schema, Classes are generated for "Document,
"AuthorType", "EditorType" and "tag".
The "Document" class contains member property called "tagField" of type
"tag".
So i can, in code say:
tag t = Document.tag

the tag class will contain accessors for retrieving arrays containing
items of types "EditorType" and "AuthorType".

The issue is when i retrieve the "tag" object from the autogenerated
class and then attempt to serialize that, the name space is missing.
That is because (i think), the tag class contains an
"XMLTypeAttribute(AnonymousType=true)" preceding it's class defnition.
So i changed that, removed the anonymousttype flags and added the
namespace, but now when i serialize it, only the it's child elements
contain the correct namespace.

How can i force WSD.EXE to generate this type of class correctly?

Nov 17 '05 #1
2 2328
Hi faerseer,

there is another Xml tool on gotdotnet.com called
XSD Object Code Generator which is more comfortable
than the standard XSD.exe. XSD Object Code Generator
comes as a VS PlugIn and add a new Project Type
to your IDE. It also allows you to specify the namespace
which i think will solve your problems.

http://apps.gotdotnet.com/xmltools/xsdobjgen/

Cheers
Lars Behrmann

_________________
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/

farseer schrieb:
Hi,
First, sorry for this long post, but i'd like to explain my problem in
detail...
i have generated some classes from my schema. Classes are generated
for the root (overall document), complexTypes with complexContents
(this is how my types in the xsd are defined), and elements defined as
complextypes that contain more than one unbounded child elements.

THe problem i am having is when i serialize Fragments of these classes
back to xml, the namespace does NOT appear for certain elements being
written. It seems that XSD.exe writes an XMLRootAttribute for the top
level root element, an XMLTypeAttribute for the complextypes with
complexContent, BUT writes an "XmlAttribute(AnonymousType=True)" for
the last case: classed based on elements defined as compexTypes that
contain more than one unbounded child elements. This means when this
class is serialized, no namespace is outputed. Further, if i manually
change the autogenerated code, the namespace is outputed for the child
elements defined in that class, but not for the toplevel element that
class represents.

Here's an example of what i a talking about

if i have a schema that looks like this:

<xsd:element name="Document">
<xsd:element name="title" type="xsd:string" type="xsd:anyType"/>
<xsd:element name="description" type="xsd:string"
type="xsd:string"/>
<xsd:element ref="tags" minOccurs="0" />

<xsd:element name="tags">
<xsd:complexType mixed="true">
<xsd:all>
<xsd:element ref="authors" minOccurs="0" />
<xsd:element ref="editors" minOccurs="0" />
...
</xsd:all>
</xsd:comlexType>
</xsd:element>

<xsd:element name="authors" />
<xsd:complexType>
<xsd:sequence>
<xsd:element name="author" type="AuthorType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="editors" />
<xsd:complexType>
<xsd:sequence>
<xsd:element name="editor" type="EditorType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name = "AuthorType">
<xsd:complexContent>
....
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name = "EditorType">
<xsd:complexContent>
....
</xsd:complexContent>
</xsd:complexType>

...
</xsd:element>

With the above schema, Classes are generated for "Document,
"AuthorType", "EditorType" and "tag".
The "Document" class contains member property called "tagField" of type
"tag".
So i can, in code say:
tag t = Document.tag

the tag class will contain accessors for retrieving arrays containing
items of types "EditorType" and "AuthorType".

The issue is when i retrieve the "tag" object from the autogenerated
class and then attempt to serialize that, the name space is missing.
That is because (i think), the tag class contains an
"XMLTypeAttribute(AnonymousType=true)" preceding it's class defnition.
So i changed that, removed the anonymousttype flags and added the
namespace, but now when i serialize it, only the it's child elements
contain the correct namespace.

How can i force WSD.EXE to generate this type of class correctly?


Nov 17 '05 #2
Thank you Lars. i will try this new tool

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Aleksei Guzev | last post: by
4 posts views Thread by Wayne Wengert | last post: by
1 post views Thread by Ivo Bronsveld | last post: by
2 posts views Thread by Tobias Zimmergren | last post: by
8 posts views Thread by Joe | last post: by
2 posts views Thread by Simon | last post: by
7 posts views Thread by fjlaga | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.