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

Deserializing primitive element with attribute

I think this XML response sucks, but it's being sent to us from a
third-party, so I can't do anything about it except work with it.

I am receiving the following return code elements inside a response:

<Response>
<RC1 message="SUCCESS">0</RC1>
<RC2 message="Blah blah blah">1</RC2>
</Response>

Now, if I make RC1 and RC2 "int" members of a Response class, it parses
the 0 and 1 correctly, but misses the "SUCCESS" and "Blah blah blah".
If i create a class called RC that has an [XmlAttribute] named
"message", it parses the message properly, but I have no idea how to
access the values 0 and 1 because they have no tag.

Any ideas?

--- Deserializing routine ---
XmlSerializer xs = new XmlSerializer(typeof(Response));
MemoryStream memoryStream = new
MemoryStream(StringToUTF8ByteArray(strXml));
Response r = (Response)xs.Deserialize(memoryStream);

-- RC class, loses the 0/1 value --
public class RC
{
public int ReturnCode;

[XmlAttribute]
public string message;

public RC()
{
ReturnCode = -999;
message = "NULL";
}
}

-- The other way, lose the message attribute --
public class Response
{
public int RC1;
public int RC2;
}

Dec 7 '05 #1
2 1329
Add the following to your RC class:

[System.Xml.Serializerion.XmlText]
public string Value;

"voipdealer" <vo********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I think this XML response sucks, but it's being sent to us from a
third-party, so I can't do anything about it except work with it.

I am receiving the following return code elements inside a response:

<Response>
<RC1 message="SUCCESS">0</RC1>
<RC2 message="Blah blah blah">1</RC2>
</Response>

Now, if I make RC1 and RC2 "int" members of a Response class, it parses
the 0 and 1 correctly, but misses the "SUCCESS" and "Blah blah blah".
If i create a class called RC that has an [XmlAttribute] named
"message", it parses the message properly, but I have no idea how to
access the values 0 and 1 because they have no tag.

Any ideas?

--- Deserializing routine ---
XmlSerializer xs = new XmlSerializer(typeof(Response));
MemoryStream memoryStream = new
MemoryStream(StringToUTF8ByteArray(strXml));
Response r = (Response)xs.Deserialize(memoryStream);

-- RC class, loses the 0/1 value --
public class RC
{
public int ReturnCode;

[XmlAttribute]
public string message;

public RC()
{
ReturnCode = -999;
message = "NULL";
}
}

-- The other way, lose the message attribute --
public class Response
{
public int RC1;
public int RC2;
}

Dec 7 '05 #2
Thanks, that worked.
Chris Lovett wrote:
Add the following to your RC class:

[System.Xml.Serializerion.XmlText]
public string Value;

"voipdealer" <vo********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I think this XML response sucks, but it's being sent to us from a
third-party, so I can't do anything about it except work with it.

I am receiving the following return code elements inside a response:

<Response>
<RC1 message="SUCCESS">0</RC1>
<RC2 message="Blah blah blah">1</RC2>
</Response>

Now, if I make RC1 and RC2 "int" members of a Response class, it parses
the 0 and 1 correctly, but misses the "SUCCESS" and "Blah blah blah".
If i create a class called RC that has an [XmlAttribute] named
"message", it parses the message properly, but I have no idea how to
access the values 0 and 1 because they have no tag.

Any ideas?

--- Deserializing routine ---
XmlSerializer xs = new XmlSerializer(typeof(Response));
MemoryStream memoryStream = new
MemoryStream(StringToUTF8ByteArray(strXml));
Response r = (Response)xs.Deserialize(memoryStream);

-- RC class, loses the 0/1 value --
public class RC
{
public int ReturnCode;

[XmlAttribute]
public string message;

public RC()
{
ReturnCode = -999;
message = "NULL";
}
}

-- The other way, lose the message attribute --
public class Response
{
public int RC1;
public int RC2;
}


Dec 13 '05 #3

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

Similar topics

5
by: Artur Niesporek | last post by:
Hi guys, when receiving a soap response posted back from a server i get the following error when deserializing the soap message. The problem seems to be with the item-collection of the...
3
by: Mark McConnell | last post by:
Regarding deserializing XML into a custom object... I've been able to deserialize an XML doc into my custom object and everything works great. The problem I am encountering is when one of the...
0
by: Jon Fairchild | last post by:
I am getting the following error when deserializing an XML with attribute overrides: "There is an error in XML document (2, 2) … <RulesConfig xmlns=''> was not expected" My XML looks like this:...
0
by: Peter Theill | last post by:
Hi, I'm having an issue with deserializing some xml using a proxy class generated by "xsd.exe". My proxy class contains this class definition: public class IqProfileType {
4
by: Wayne Wengert | last post by:
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in...
7
by: farseer | last post by:
Hi, i am getting an error when trying to deserialize and xml. the error is shown below. i get this error regardless if i try to desearialize in C# or VB. the XML itself does infact contain a...
1
by: Parag Mahajan | last post by:
Hello, I am getting exception when my .Net client tries to deserialize the response received. The excpetion thrown is: Unhandled Exception: System.InvalidOperationException: There is an error...
0
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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,...

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.