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

"xsi:type" missing from serialization of object- XmlSerializer

Hi,

I'm serializing an object using XmlSerializer. It is serializing, but
we are getting errors upon deserialization.

We use the following code to serialize:

FileStream fs = new FileStream(NavCmdFile, FileMode.Create,
FileAccess.Write, FileShare.None);
XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
xmlFmt.Serialize(fs, someObject);

One of the objects is a parameter and this is what you get:

<someObject_parameter>
<name>name</name>
<source>soucename</source>
<value type="xsd:int">1</value>
</someObject_parameter>

When we deserialize, this creates an error. When we edit one line it
deserializes correctly:
<value xsi:type="xsd:int">1</value>

Is there any other way to do this or any workaround which won't omit
the "xsi:" portion?

I appreciate any help in advance.

thanks,
Geoff

Dec 1 '05 #1
6 10732
And the value is it a property of type object?

Gabriel

"geoffrobinson" <ge***********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I'm serializing an object using XmlSerializer. It is serializing, but
we are getting errors upon deserialization.

We use the following code to serialize:

FileStream fs = new FileStream(NavCmdFile, FileMode.Create,
FileAccess.Write, FileShare.None);
XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
xmlFmt.Serialize(fs, someObject);

One of the objects is a parameter and this is what you get:

<someObject_parameter>
<name>name</name>
<source>soucename</source>
<value type="xsd:int">1</value>
</someObject_parameter>

When we deserialize, this creates an error. When we edit one line it
deserializes correctly:
<value xsi:type="xsd:int">1</value>

Is there any other way to do this or any workaround which won't omit
the "xsi:" portion?

I appreciate any help in advance.

thanks,
Geoff

Dec 1 '05 #2
Here is a little more detail.

In the thing referenced in the object during the serialization is the
following:
[XmlElement(ElementName = "value")]
public ParameterValues Value;

which references this class:
[Serializable]
public class ParameterValues
{
[XmlAttribute("type")]
public string Type;

[XmlText]
public int Value;

public XParameterValues(int val)
{
Type = "xsd:int";
Value=val;
}

}

____

I'm thinking there may be some issues because an XML element references
another class. But everything seems to be serializing fine except for
the lack of the 'xsi:' before the 'type' tag.

thanks again,
Geoff

Dec 1 '05 #3
[XmlAttribute("type", Namespace =
"http://www.w3.org/2001/XMLSchema-instance")]
public string Type;

Gabriel Lozano-Morán
http://www.realdn.net
Dec 1 '05 #4
Many thanks. Worked like a charm.

Dec 1 '05 #5
JMD
When you manually edit in the xsi: prefix, does it actually deserialize
correctly to the Type field in the object?

This bothers me because you specified a local (not in a namespace)
attribute named 'type', which is totally distinct from the global
xsi:type which has a special meaning in XML Schemas.

So it bothers me that you never got to the bottom of why it would not
deserialize with an attribute that happens to be named 'type'. How is
that different from all the other code out there that uses
[XmlAttribute]?

Dec 6 '05 #6
test
"geoffrobinson" <ge***********@gmail.com> ????
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I'm serializing an object using XmlSerializer. It is serializing, but
we are getting errors upon deserialization.

We use the following code to serialize:

FileStream fs = new FileStream(NavCmdFile, FileMode.Create,
FileAccess.Write, FileShare.None);
XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
xmlFmt.Serialize(fs, someObject);

One of the objects is a parameter and this is what you get:

<someObject_parameter>
<name>name</name>
<source>soucename</source>
<value type="xsd:int">1</value>
</someObject_parameter>

When we deserialize, this creates an error. When we edit one line it
deserializes correctly:
<value xsi:type="xsd:int">1</value>

Is there any other way to do this or any workaround which won't omit
the "xsi:" portion?

I appreciate any help in advance.

thanks,
Geoff

Jan 9 '06 #7

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

Similar topics

8
by: johnsocs | last post by:
How do you validate the following XML document, I'm having problems with element 'one' with the attribute xsi:type="xsd:string" <?xml version="1.0" encoding="UTF-8"?> <zero...
0
by: johnsocs | last post by:
All I'm trying to write an xml schema for the following xml from the google web service api. In the schema I'm not sure how to describe the soapenv:encodingStyle attribute. Thanks. <?xml...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
0
by: Carl Lindmark | last post by:
Hello all, I'm having some problems understanding all the ins and outs with datasets and datatables (and navigating through the filled datatable)... Just when I thought I had gotten the hang...
0
by: Kaimar Seljamäe | last post by:
Hi, I have to create a web service client which uses SOAP encoding but does not use "multi-reference" values (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513 item 10). If I...
1
by: Ganesh Muthuvelu | last post by:
Hello, Is it possible to make the dataset give the "xsi:type" data as well?. I need result from the dataset.GetXML method something like this for the column "a": <a xsi:type="int">12</a> Is...
1
by: tankbattle | last post by:
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element...
3
by: Lord0 | last post by:
I am trying to implement variable content containers using an abstract type and type substitution. My schema is as follows: <?xml version="1.0" encoding="UTF-8"?> <schema...
0
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of...
0
by: lamagra | last post by:
Hello all, I first wanted to say that this is my first post and thank you for taking a look at it. My question: I am trying to write an XML Parser using the Lib:XML package. The problem that...
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
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...

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.