473,414 Members | 1,989 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,414 software developers and data experts.

XML Serialization bug?

AP
Take a class:

public class AClass {
public bool FurtherActionsRequired;
public bool FurtherActionsRequiredSpecified;
}

this class serialized to XML produces the following XML output:

<?xml version="1.0" encoding="utf-8"?>
<AClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FurtherActionsRequiredSpecified>false</FurtherActionsRequiredSpecified>
</AClass>

Why does FurtherActionsRequired not get serialized to XML? Is this a bug?

Adam
Nov 12 '05 #1
4 1461
Adam,

Was my last explanation not helpful at all?

Basically, your value-type fields won't serialize without the extra helper
fields.

Jiho

"AP" <ad***@indra.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
Take a class:

public class AClass {
public bool FurtherActionsRequired;
public bool FurtherActionsRequiredSpecified;
}

this class serialized to XML produces the following XML output:

<?xml version="1.0" encoding="utf-8"?>
<AClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FurtherActionsRequiredSpecified>false</FurtherActionsRequiredSpecified>
</AClass>

Why does FurtherActionsRequired not get serialized to XML? Is this a bug?

Adam

Nov 12 '05 #2
AP
No it wasn't. Why does one serialize and not the other?

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
Adam,

Was my last explanation not helpful at all?

Basically, your value-type fields won't serialize without the extra helper
fields.

Jiho

"AP" <ad***@indra.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
Take a class:

public class AClass {
public bool FurtherActionsRequired;
public bool FurtherActionsRequiredSpecified;
}

this class serialized to XML produces the following XML output:

<?xml version="1.0" encoding="utf-8"?>
<AClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FurtherActionsRequiredSpecified>false</FurtherActionsRequiredSpecified>
</AClass>

Why does FurtherActionsRequired not get serialized to XML? Is this a bug?
Adam


Nov 12 '05 #3
This is a documented feature.
http://msdn.microsoft.com/library/en...ClassTopic.asp

If you have in a single class
fieldName
and
fieldNameSpecified

where fieldName is anything and fieldNameSpecified is a bool, the latter is
treated specially. It indicates whether the field "fieldName" has been
specified. If false, then "fieldName" will not be serialized.

This means if you extended your original example class to be:
public class AClass {
/* 1 */ public bool FurtherActionsRequired;
/* 2 */ public bool FurtherActionsRequiredSpecifiedXXX;
/* 3 */ public bool FurtherActionsRequiredSpecified;
/* 4 */ public bool FurtherActionsRequiredSpecifiedSpecified;
}

And if you had an instance of this class in which all fields were false,
then you would serialize only the 2nd and 4th fields.
The 3rd field, being false, would tell the serializer to ignore the 1st
field.
The 4th field, likewise, would tell the serializer to ignore the 3rd field.
No fields would tell the serializer to ignore the 2nd or 4th fields so they
would be serialized.

If you set all these fields to true, then all fields will be serialized.

Typically the specially named "***Specified" field is attributed with an
XmlIgnore attribute so that it is not serialized, ever.
See the doc I referenced above for the details and an example.
-Dino

"AP" <ad***@indra.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
No it wasn't. Why does one serialize and not the other?

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
Adam,

Was my last explanation not helpful at all?

Basically, your value-type fields won't serialize without the extra helper
fields.

Jiho

"AP" <ad***@indra.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
Take a class:

public class AClass {
public bool FurtherActionsRequired;
public bool FurtherActionsRequiredSpecified;
}

this class serialized to XML produces the following XML output:

<?xml version="1.0" encoding="utf-8"?>
<AClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FurtherActionsRequiredSpecified>false</FurtherActionsRequiredSpecified> </AClass>

Why does FurtherActionsRequired not get serialized to XML? Is this a

bug?
Adam



Nov 12 '05 #4
eh, I guess I was a little off. :)

"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:u%****************@tk2msftngp13.phx.gbl...
This is a documented feature.
http://msdn.microsoft.com/library/en...ClassTopic.asp
If you have in a single class
fieldName
and
fieldNameSpecified

where fieldName is anything and fieldNameSpecified is a bool, the latter is treated specially. It indicates whether the field "fieldName" has been
specified. If false, then "fieldName" will not be serialized.

This means if you extended your original example class to be:
public class AClass {
/* 1 */ public bool FurtherActionsRequired;
/* 2 */ public bool FurtherActionsRequiredSpecifiedXXX;
/* 3 */ public bool FurtherActionsRequiredSpecified;
/* 4 */ public bool FurtherActionsRequiredSpecifiedSpecified;
}

And if you had an instance of this class in which all fields were false,
then you would serialize only the 2nd and 4th fields.
The 3rd field, being false, would tell the serializer to ignore the 1st
field.
The 4th field, likewise, would tell the serializer to ignore the 3rd field. No fields would tell the serializer to ignore the 2nd or 4th fields so they would be serialized.

If you set all these fields to true, then all fields will be serialized.

Typically the specially named "***Specified" field is attributed with an
XmlIgnore attribute so that it is not serialized, ever.
See the doc I referenced above for the details and an example.
-Dino

"AP" <ad***@indra.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
No it wasn't. Why does one serialize and not the other?

"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
Adam,

Was my last explanation not helpful at all?

Basically, your value-type fields won't serialize without the extra helper fields.

Jiho

"AP" <ad***@indra.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
> Take a class:
>
> public class AClass {
> public bool FurtherActionsRequired;
> public bool FurtherActionsRequiredSpecified;
> }
>
> this class serialized to XML produces the following XML output:
>
> <?xml version="1.0" encoding="utf-8"?>
> <AClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <FurtherActionsRequiredSpecified>false</FurtherActionsRequiredSpecified> > </AClass>
>
> Why does FurtherActionsRequired not get serialized to XML? Is this
a bug?
>
> Adam
>
>



Nov 12 '05 #5

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

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
5
by: Nikola Skoric | last post by:
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK until I tried to desirialize a object. There the program died abruptly dumping this: System.ArgumentOutOfRangeException:...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
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?
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
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,...
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...
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.