Serializing classes generated by XSD.exe

  • Thread starter Thread starter farseer
  • Start date Start date
F

farseer

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?
 
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/
 
Back
Top