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

XML Serialization

Hello all...

My problem is this.. I have an XML that has been formatted and given to me
already. My goal is to attempt to serialize the XML into an object using a
regular class and XMLSerializer if possible. I don't want to stroll too far
outside the realm of "normal". My main problem is that in my XML, I have a
node called "Referrals" which has both an array of Referral nodes under it
AS WELL AS a lot of attributes. I need to have both the attributes and all
array nodes accessable through my class. I am able to get either the
attributes OR the Array, but I cannot get both. I have something wrong, and
I am completely stumped.

Anyway... I will first post the XML I am trying to serialize and then I will
post the class that I'm using to attempt to serialize, and someone might be
able to help me out a little?

<User ID="1234567" Email="no****@email.com" OfferComplete="0"
ReferralsComplete="0" Approved="0" Hold="0">

<Orders OrderCount="1">
<Order OrderNumber="1234567" OrderStatus="Shipped"
TrackingNumber="ZA1234567890"/>
</Orders>

<Referrals ReferralsRequired="5" Stage3Count="1" Stage2Count="1"
Stage1Count="1" Stage0Count="1">
<Referral ToName="On Hold" Email="ho**@email.com" ReferralStage="0"
ReferralStageText="Referral denied"/>
<Referral ToName="Not Joined" Email="no****@email.com" ReferralStage="1"
ReferralStageText="Referral has not joined"/>
<Referral ToName="Joined" Email="jo****@email.com" ReferralStage="2"
ReferralStageText="Joined, but offer not completed"/>
<Referral ToName="Completed" Email="co******@email.com"
ReferralStage="3" ReferralStageText="Offer Completed"/>
</Referrals>

</User>
[XmlRootAttribute("User", Namespace="", IsNullable=false)]
public class User
{
[XmlAttribute]
public string ID;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string OfferComplete;
[XmlAttribute]
public string ReferralsComplete;
[XmlAttribute]
public string Approved;
[XmlAttribute]
public string Hold;

/* Uncomment this section to get the
Array Attributes properly
but not the Array Elements */
/*
public clsReferrals Referrals;
public class clsReferrals
{
[XmlAttribute]
public string ReferralsRequired;
[XmlAttribute]
public string Stage3Count;
[XmlAttribute]
public string Stage2Count;
[XmlAttribute]
public string Stage1Count;
[XmlAttribute]
public string Stage0Count;

[XmlArrayItem(ElementName="Referral")]
public clsReferral[] Referrals;
public class clsReferral
{
[XmlAttribute]
public string ToName;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string ReferralStage;
[XmlAttribute]
public string ReferralStageText;
}
}
*/

/* Uncomment this section to get the
Array Elements properly */
/*
[XmlArrayItem(ElementName="Referral")]
public clsReferral[] Referrals;
public class clsReferral
{
[XmlAttribute]
public string ToName;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string ReferralStage;
[XmlAttribute]
public string ReferralStageText;
}
*/
}
Nov 12 '05 #1
1 3334
Ok..

I finally got it after playing around with it... I thought I had tried this
before, but obviously not..

Anyway.. for anyone interested, the final class looked like this...

[XmlRootAttribute("User", Namespace="", IsNullable=false)]
public class User
{
[XmlAttribute]
public string ID;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string OfferComplete;
[XmlAttribute]
public string ReferralsComplete;
[XmlAttribute]
public string Approved;
[XmlAttribute]
public string Hold;

[XmlElement("Referrals")]
public clsReferrals Referrals;
public class clsReferrals
{
[XmlAttribute]
public string ReferralsRequired;
[XmlAttribute]
public string Stage3Count;
[XmlAttribute]
public string Stage2Count;
[XmlAttribute]
public string Stage1Count;
[XmlAttribute]
public string Stage0Count;

[XmlElement("Referral")]
public clsReferral[] Referral;
public class clsReferral
{
[XmlAttribute]
public string ToName;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string ReferralStage;
[XmlAttribute]
public string ReferralStageText;
}
}
}
"Drakier Dominaeus" <dr*****@hotmail.com> wrote in message
news:hbp6d.26447$7k.10465@okepread05...
Hello all...

My problem is this.. I have an XML that has been formatted and given to me
already. My goal is to attempt to serialize the XML into an object using a
regular class and XMLSerializer if possible. I don't want to stroll too
far outside the realm of "normal". My main problem is that in my XML, I
have a node called "Referrals" which has both an array of Referral nodes
under it AS WELL AS a lot of attributes. I need to have both the
attributes and all array nodes accessable through my class. I am able to
get either the attributes OR the Array, but I cannot get both. I have
something wrong, and I am completely stumped.

Anyway... I will first post the XML I am trying to serialize and then I
will post the class that I'm using to attempt to serialize, and someone
might be able to help me out a little?

<User ID="1234567" Email="no****@email.com" OfferComplete="0"
ReferralsComplete="0" Approved="0" Hold="0">

<Orders OrderCount="1">
<Order OrderNumber="1234567" OrderStatus="Shipped"
TrackingNumber="ZA1234567890"/>
</Orders>

<Referrals ReferralsRequired="5" Stage3Count="1" Stage2Count="1"
Stage1Count="1" Stage0Count="1">
<Referral ToName="On Hold" Email="ho**@email.com" ReferralStage="0"
ReferralStageText="Referral denied"/>
<Referral ToName="Not Joined" Email="no****@email.com"
ReferralStage="1" ReferralStageText="Referral has not joined"/>
<Referral ToName="Joined" Email="jo****@email.com" ReferralStage="2"
ReferralStageText="Joined, but offer not completed"/>
<Referral ToName="Completed" Email="co******@email.com"
ReferralStage="3" ReferralStageText="Offer Completed"/>
</Referrals>

</User>
[XmlRootAttribute("User", Namespace="", IsNullable=false)]
public class User
{
[XmlAttribute]
public string ID;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string OfferComplete;
[XmlAttribute]
public string ReferralsComplete;
[XmlAttribute]
public string Approved;
[XmlAttribute]
public string Hold;

/* Uncomment this section to get the
Array Attributes properly
but not the Array Elements */
/*
public clsReferrals Referrals;
public class clsReferrals
{
[XmlAttribute]
public string ReferralsRequired;
[XmlAttribute]
public string Stage3Count;
[XmlAttribute]
public string Stage2Count;
[XmlAttribute]
public string Stage1Count;
[XmlAttribute]
public string Stage0Count;

[XmlArrayItem(ElementName="Referral")]
public clsReferral[] Referrals;
public class clsReferral
{
[XmlAttribute]
public string ToName;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string ReferralStage;
[XmlAttribute]
public string ReferralStageText;
}
}
*/

/* Uncomment this section to get the
Array Elements properly */
/*
[XmlArrayItem(ElementName="Referral")]
public clsReferral[] Referrals;
public class clsReferral
{
[XmlAttribute]
public string ToName;
[XmlAttribute]
public string Email;
[XmlAttribute]
public string ReferralStage;
[XmlAttribute]
public string ReferralStageText;
}
*/
}

Nov 12 '05 #2

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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.