473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2492
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
4
by: Wayne Wengert | last post by:
I am still stuck trying to create a Class to use for exporting and importing array data to/from XML. The format of the XML that I want to import/export is shown below as is the Class and the code I...
1
by: Ivo Bronsveld | last post by:
All, I have quite a challenging task ahead of me. I need to write an object model (for code access) based on a schema, which cannot be made into a dataset because of it's complexity. So I...
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
8
by: Joe | last post by:
Hello All: Say I have a solution with two projects (Project1 and Project2) and each project contains a class (Project1 contains Class1 and Project2 contains Class2). The projects don't...
2
by: Simon | last post by:
I'm developing a new application and want to use serialization as a way to save my data. But as I add new variables to my classes, how will serializing cope with that? For example, suppose I have...
2
by: farseer | last post by:
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),...
7
by: fjlaga | last post by:
I have written an Office Add-in for Excel using VB.NET and the .NET 1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I want to add a User Settings/Prefereneces dialog and allow...
2
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.