473,399 Members | 2,146 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,399 software developers and data experts.

simple .net xml serialization not working

I have a type in a schema:

<xs:complexType name="SimpleExt">
<xs:simpleContent>
<xs:extension base="xs:int">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

which I run xsd.exe /c on. It creates the following class:

/// <remarks/>
public class SimpleExt {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name;

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public int Value;
}

When I compile the class and run xsd.exe on the dll, I get:

<xs:complexType name="SimpleExt">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string"
/>
<xs:element minOccurs="1" maxOccurs="1" name="Value" type="xs:int" />
</xs:sequence>
</xs:complexType>

This is clearly not what I want. I need to define a class that will
generate the original schema. As you can see, the second schema didn't even
honor my attributes. What must I do in my class to do that? Is this a
xsd.exe limitation?

Thanks and I appreciate your help.
Jiho
Nov 12 '05 #1
1 1764
The XML generated when you serialize an object of the SimpleExt class is
valid against your original schema. It will also validate against the new
schema you extracted from the compiled class. However, there is not
information in the class that XSD.exe generated to extract the original
schema. There is no way to store the detail about your XML schema in the
class' metadata so XSD generates a somewhat canonical schema that will
validate the type serialized to XML. The XSD.exe tool does not consider any
constraints such as extension or restriction. That's a known limitation of
the tool.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
I have a type in a schema:

<xs:complexType name="SimpleExt">
<xs:simpleContent>
<xs:extension base="xs:int">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

which I run xsd.exe /c on. It creates the following class:

/// <remarks/>
public class SimpleExt {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name;

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public int Value;
}

When I compile the class and run xsd.exe on the dll, I get:

<xs:complexType name="SimpleExt">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string"
/>
<xs:element minOccurs="1" maxOccurs="1" name="Value" type="xs:int" /> </xs:sequence>
</xs:complexType>

This is clearly not what I want. I need to define a class that will
generate the original schema. As you can see, the second schema didn't even honor my attributes. What must I do in my class to do that? Is this a
xsd.exe limitation?

Thanks and I appreciate your help.
Jiho

Nov 12 '05 #2

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

Similar topics

3
by: Aamir | last post by:
Hi, Quick Question: How to create a simple XML with US States list and read it into a combo box. Detail: I am very new to Dot Net technology as well as xml. I am building a desktop app in...
2
by: Dave Veeneman | last post by:
I'm working on a project where I have to persist data to a file, rather than to a database. Basically, I need to save the state of several classes, each of which will have a couple of dozen...
2
by: ofer | last post by:
Hi, I am working with the beta version of the new .net framework (Whidbey) and I encountered a problem with serialization that did'nt exist in the .net 2003 the situation is like this : I have...
5
by: Tamir Khason | last post by:
Hi, all Two classes Foo1 and Foo2 Foo1 uses Foo2 as reference Both are strong name signed with the same key pair I'm performing Binary Serialization of object inside Foo2 from Foo1 as following:...
1
by: Farouche | last post by:
Hi all I have made two simple methods to serialize/deserialize a simple data structure to my database using SoapFormatting. This actually works just great, when the structures stays the same....
2
by: Thomas T. Veldhouse | last post by:
Hello. I have been working with a client of mine on their seriazation code and we seem to have run into an issue when we migrated from .NET 1.1 to .NET 2.0. We have a framework of business...
2
by: Ron M. Newman | last post by:
Hi, I have a simple class that has a Hashtable. the hashtable has a couple of key/value pairs where the key is a string and the value is also a strong. I have at the top of that class. ...
6
by: pamela fluente | last post by:
Hi, please find below a very simple code snippet which is giving me the following error: System.Runtime.Serialization.SerializationException was unhandled Message="The constructor to deserialize...
5
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
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
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,...

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.