473,703 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 XMLRootAttribut e for the top
level root element, an XMLTypeAttribut e for the complextypes with
complexContent, BUT writes an "XmlAttribute(A nonymousType=Tr ue)" 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:strin g" type="xsd:anyTy pe"/>
<xsd:element name="descripti on" type="xsd:strin g"
type="xsd:strin g"/>
<xsd:element ref="tags" minOccurs="0" />

<xsd:element name="tags">
<xsd:complexTyp e 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:complexTyp e>
<xsd:sequence >
<xsd:element name="author" type="AuthorTyp e" />
</xsd:sequence>
</xsd:complexType >
</xsd:element>
<xsd:element name="editors" />
<xsd:complexTyp e>
<xsd:sequence >
<xsd:element name="editor" type="EditorTyp e" />
</xsd:sequence>
</xsd:complexType >
</xsd:element>

<xsd:complexTyp e name = "AuthorType ">
<xsd:complexCon tent>
....
</xsd:complexCont ent>
</xsd:complexType >
<xsd:complexTyp e name = "EditorType ">
<xsd:complexCon tent>
....
</xsd:complexCont ent>
</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
"XMLTypeAttribu te(AnonymousTyp e=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 2517
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 XMLRootAttribut e for the top
level root element, an XMLTypeAttribut e for the complextypes with
complexContent, BUT writes an "XmlAttribute(A nonymousType=Tr ue)" 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:strin g" type="xsd:anyTy pe"/>
<xsd:element name="descripti on" type="xsd:strin g"
type="xsd:strin g"/>
<xsd:element ref="tags" minOccurs="0" />

<xsd:element name="tags">
<xsd:complexTyp e 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:complexTyp e>
<xsd:sequence >
<xsd:element name="author" type="AuthorTyp e" />
</xsd:sequence>
</xsd:complexType >
</xsd:element>
<xsd:element name="editors" />
<xsd:complexTyp e>
<xsd:sequence >
<xsd:element name="editor" type="EditorTyp e" />
</xsd:sequence>
</xsd:complexType >
</xsd:element>

<xsd:complexTyp e name = "AuthorType ">
<xsd:complexCon tent>
....
</xsd:complexCont ent>
</xsd:complexType >
<xsd:complexTyp e name = "EditorType ">
<xsd:complexCon tent>
....
</xsd:complexCont ent>
</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
"XMLTypeAttribu te(AnonymousTyp e=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
3295
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 ‘DataItem’ public class DataItem { public DataItem() {}
4
2729
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 am using to create a sample XML file. I am trying to dimension the ArrayOfJudgeEntity to have two sets of the JudgeTableEntity values. When I run the code I get an error that the XML is not correct. I jsut can't get my head around the array...
1
2085
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 created a couple of objects and serializing it into XML based upon the schema works perfectly. The XML / Schema looks something like this:
2
3519
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: + More ways to contact me __________________________________________________________________
8
1397
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 reference each other. Here's my question: can I serialize Class1 and use the serialized XML in Class2? How would Class2 de-serialize the XML to retrieve the Class1's properties? I don't see how I can do this since Project2 doesn't even know about...
2
1338
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 a class called Point which has 2 variables X and Y. I save a few jobs (by serializing), and then enhance my application by adding a Z variable. How will serializing behave when loading those jobs that were created before Z was added?
2
4924
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), 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...
7
2823
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 the user to specify some settings and I need to persist these settings between runs. I made a serializable class which uses the BinaryFormatter to serialize/deserialize the setttings. Serialization works great. However, when I try to...
2
697
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 UserControl are like that). When serializing, how could I ignore all the properties coming from the UserControl class? I know there is XmlIgnoreAttribute, but how could I set it to every property of UserControl, as it is not my class? Thank you...
0
8759
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8669
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8963
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6588
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2069
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.