so i have this problem i`m trying to serialize my classes to the point that they will look like this:
<orders>
<order>
<ordersID>22070</ordersID>
<ordersTotal>53.00</ordersTotal>
<prod>
<productCount>1</productCount>
<productPrice>2.00</productPrice>
<productPricePromo>0.00</productPricePromo>
<productDiscount>0</productDiscount>
<productName>Шампоан против косопад Loreal Density Advanced 500 мл.</productName>
<productNumber>30055</productNumber>
</prod>
<prod>
<productCount>1</productCount>
<productPrice>6.00</productPrice>
<productPricePromo>0.00</productPricePromo>
<productDiscount>0</productDiscount>
<productName>Маска за суха коса Loreal Интенс Рипер 200 мл.</productName>
<productNumber>30107</productNumber>
</prod>
</order>
</orders>
But whatever i try e end up like this:
<?xml version="1.0" encoding="UTF-8"?>
<orders xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<order>
<order>
<ordersID>0</ordersID>
<ordersTotal>0</ordersTotal>
<products>
<progducts>
<productCount>0</productCount>
<productPrice>0</productPrice>
<productPricePromo>0</productPricePromo>
<productDiscount>0</productDiscount>
<productNumber>0</productNumber>
</progducts>
<progducts>
<productCount>0</productCount>
<productPrice>0</productPrice>
<productPricePromo>0</productPricePromo>
<productDiscount>0</productDiscount>
<productNumber>0</productNumber>
</progducts>
</products>
</order>
</order>
</orders>
The problem is the names of the second and third class i`m using is geting listed as tags aswell inside the xml. So my question is: is there any way around this?
Here is my code aswell.
Classes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace testXML
{
[Serializable]
public class orders
{
private List <order> m_order = new List <order>();
[XmlArrayItem(typeof(order))]
public List<order> order
{
get { return m_order; }
set { m_order = value; }
}
}
[Serializable]
public class order
{
public int ordersID { get; set; }
public double ordersTotal { get; set; }
private List<progducts> prod = new List<progducts>();
[XmlArrayItem(typeof(progducts))]
public List<progducts> products
{
get { return prod; }
set { prod = value; }
}
}
[Serializable]
public class progducts
{
public string productName { get; set; }
public int productCount { get; set; }
public double productPrice { get; set; }
public double productPricePromo { get; set; }
public double productDiscount { get; set; }
public Int64 productNumber { get; set; }
}
}
And here is the execution code:
orders f = new orders();
order or = new order();
progducts p1 = new progducts();
progducts p2 = new progducts();
f.order.Add(or);
or.products.Add(p1);
or.products.Add(p2);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(orders));
TextWriter writer = new StreamWriter("Family.xml");
xmlSerializer.Serialize(writer, f);
writer.Close();
Thank you for any help in advance!
Replace the [XmlArrayItem(typeof(order))] with [XmlElement("order")] and [XmlArrayItem(typeof(progducts))] with [XmlElement("prod")]. That will remove one level when serializing the lists.
Just add another attributes to your property order like this:
[XmlArray("orders")]
[XmlArrayItem("order", typeof(order))]
public List<order> order
{
get { return m_order; }
set { m_order = value; }
}
That should work.
If you use the following classes which were generated using xsd.exe:
using System.Xml.Serialization;
using System;
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class orders
{
private ordersOrder orderField;
public ordersOrder order
{
get
{
return this.orderField;
}
set
{
this.orderField = value;
}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class ordersOrder
{
private int ordersIDField;
private double ordersTotalField;
private ordersOrderProd[] prodField;
public int ordersID
{
get
{
return this.ordersIDField;
}
set
{
this.ordersIDField = value;
}
}
public double ordersTotal
{
get
{
return this.ordersTotalField;
}
set
{
this.ordersTotalField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute("prod")]
public ordersOrderProd[] prod
{
get
{
return this.prodField;
}
set
{
this.prodField = value;
}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class ordersOrderProd
{
private int productCountField;
private double productPriceField;
private double productPricePromoField;
private double productDiscountField;
private string productNameField;
private Int64 productNumberField;
public int productCount
{
get
{
return this.productCountField;
}
set
{
this.productCountField = value;
}
}
public double productPrice
{
get
{
return this.productPriceField;
}
set
{
this.productPriceField = value;
}
}
public double productPricePromo
{
get
{
return this.productPricePromoField;
}
set
{
this.productPricePromoField = value;
}
}
public double productDiscount
{
get
{
return this.productDiscountField;
}
set
{
this.productDiscountField = value;
}
}
public string productName
{
get
{
return this.productNameField;
}
set
{
this.productNameField = value;
}
}
public Int64 productNumber
{
get
{
return this.productNumberField;
}
set
{
this.productNumberField = value;
}
}
}
Then the following code:
var orders = new orders
{
order = new ordersOrder
{
ordersID = 1,
ordersTotal = 1,
prod = new ordersOrderProd[]
{
new ordersOrderProd
{
productCount = 1,
productDiscount = 8.4,
productName = "Widget",
productNumber = 987987,
productPrice = 78.9,
productPricePromo = 68.75
}
}
}
};
XmlSerializer xmlSerializer = new XmlSerializer(typeof(orders));
TextWriter writer = new StreamWriter(".\\Family.xml");
xmlSerializer.Serialize(writer, orders);
writer.Close();
Gives you the following output:
<?xml version="1.0" encoding="utf-8"?>
<orders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<order>
<ordersID>1</ordersID>
<ordersTotal>1</ordersTotal>
<prod>
<productCount>1</productCount>
<productPrice>78.9</productPrice>
<productPricePromo>68.75</productPricePromo>
<productDiscount>8.4</productDiscount>
<productName>Widget</productName>
<productNumber>987987</productNumber>
</prod>
</order>
</orders>
You can use a serialization attribute to change the names of the XML elements or attributes you want to represent your class structure. See MSDN
Related
I am developing an UWP app using the Creators Update SDK.
I am trying to serialize a ObservableCollection ignoring a property of their class.
Here is my code, it have my class and the methods to serialize, you can see I am using [DataContract] and [IgnoreDataMember] but it's not working.
public class Classes
{
[DataContract]
public class Car : BindableBase
{
[DataMember]
private string _Name;
public string Name
{
get { return _Name; }
set { Set(ref _Name, value); }
}
[DataMember]
private string _Brand;
public string Brand
{
get { return _Brand; }
set { Set(ref _Brand, value); }
}
[IgnoreDataMember]
private bool _Electric;
public bool Electric
{
get { return _Electric; }
set { Set(ref _Electric, value); }
}
[DataMember]
private double _Price;
public double Price
{
get { return _Price; }
set { Set(ref _Price, value); }
}
}
public class Values_Car : ObservableCollection<Car> { }
public static class Garage
{
public static Values_Car Cars = new Values_Car();
static Garage()
{
}
}
[XmlRoot("Root")]
public class GarageDTO
{
[XmlElement]
public Values_Car Cars { get { return Garage.Cars; } }
}
}
public class NewSerialization
{
private static void FillList()
{
Car e_1 = new Car()
{
Name = "element_Name",
Brand = "element_Brand",
Electric = true,
Price = 1,
};
Car e_2 = new Car()
{
Name = "element_Name",
Brand = "element_Brand",
Electric = true,
Price = 2,
};
Garage.Cars.Add(e_1);
Garage.Cars.Add(e_2);
}
public static string Serializer()
{
FillList();
var _Instance = new GarageDTO();
var serializer = new XmlSerializer(typeof(GarageDTO));
using (var stream_original = new MemoryStream())
{
serializer.Serialize(stream_original, _Instance);
string string_original = string.Empty;
stream_original.Position = 0;
using (StreamReader reader = new StreamReader(stream_original, Encoding.Unicode))
{
string_original = reader.ReadToEnd();
}
return string_original;
}
}
}
using NewSerialization.Serializer(); I got:
But in the xml I got the Electric property which is ignored.
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Cars>
<Name>element_Name</Name>
<Brand>element_Brand</Brand>
<Electric>true</Electric>
<Price>1</Price>
</Cars>
<Cars>
<Name>element_Name</Name>
<Brand>element_Brand</Brand>
<Electric>true</Electric>
<Price>2</Price>
</Cars>
</Root>
How I can ignoring a property of my ObservableCollection on serialization?
Appreciate your help.
Thanks to the comments of #dbc and #Aluan Haddad I found the exact I was finding, this should be my class to achieve that:
public class Car : BindableBase
{
private string _Name;
public string Name
{
get { return _Name; }
set { Set(ref _Name, value); }
}
private string _Brand;
public string Brand
{
get { return _Brand; }
set { Set(ref _Brand, value); }
}
private bool _Electric;
[XmlIgnore] //<----This!
public bool Electric
{
get { return _Electric; }
set { Set(ref _Electric, value); }
}
private double _Price;
public double Price
{
get { return _Price; }
set { Set(ref _Price, value); }
}
}
I am trying to create a function to parse an XML file like this:
<?xml version="1.0" encoding="utf-8"?>
<list name="Grocery List" author="Ian" desc="Saturday grocery list">
<item color="black" done="false">Milk</item>
<item color="black" done="false">Eggs</item>
<item color="blue" done="false">Water</item>
</list>
It parses the attributes correctly, but it fails to return the values of the list items. Here is the function and class it uses:
class List
{
public string[] listItems;
public string[] colorArray;
public string[] doneArray;
public string listName;
public string listAuthor;
public string listDesc;
public string err;
}
Reader definition:
class ListReader
{
public List doListParse(string filename)
{
List l = new List();
int arrayCount = 0;
try
{
XmlReader r = XmlReader.Create(filename);
while (r.Read())
{
if (r.NodeType == XmlNodeType.Element && r.Name == "list")
{
//Get the attributes of the list
l.listName = r.GetAttribute("name");
l.listAuthor = r.GetAttribute("author");
l.listDesc = r.GetAttribute("desc");
while (r.NodeType != XmlNodeType.EndElement)
{
r.Read();
if (r.Name == "item")
{
r.Read();
if (r.NodeType == XmlNodeType.Text)
{
//Get The Attributes
l.colorArray[arrayCount] = r.GetAttribute("color");
l.doneArray[arrayCount] = r.GetAttribute("done");
//Get The Content
l.listItems[arrayCount] = r.Value.ToString();
arrayCount++;
}
r.Read();
}
}
}
}
}
catch (Exception e)
{
l.err = e.ToString();
}
return l;
}
}
When I execute the program, it gives this exception:
System.NullReferenceException: Object reference not set to an instance of an object.
What is going on here?
I'd recommend you using a serializer. The XmlSerializer class is pretty decent. It will simplify your code.
So start by defining the models that will map to this XML structure:
[XmlRoot("list")]
public class GroceryList
{
[XmlAttribute("name")]
public string Name { get; set; }
[XmlAttribute("author")]
public string Author { get; set; }
[XmlAttribute("desc")]
public string Description { get; set; }
[XmlElement("item")]
public Item[] Items { get; set; }
}
public class Item
{
[XmlAttribute("color")]
public string Color { get; set; }
[XmlAttribute("done")]
public bool Done { get; set; }
[XmlText]
public string Value { get; set; }
}
and then simply deserialize the XML:
class Program
{
static void Main()
{
var serializer = new XmlSerializer(typeof(GroceryList));
using (var reader = XmlReader.Create("groceriesList.xml"))
{
var list = (GroceryList)serializer.Deserialize(reader);
// you could access the list items here
}
}
}
You can use Linq To Xml.
var xElem = XDocument.Parse(xml).Element("list"); //or XDocument.Load(filename)
var list = new
{
Name = xElem.Attribute("name").Value,
Author = xElem.Attribute("author").Value,
Desc = xElem.Attribute("desc").Value,
Items = xElem.Elements("item")
.Select(e => new{
Color = e.Attribute("color").Value,
Done = (bool)e.Attribute("done"),
Value = e.Value,
})
.ToList()
};
I wanna serialize this class:
[Serializable]
[XmlRoot(ElementName = "Rates")]
public class CbrRate : IRate
{
public CbrRate()
{
}
public CbrRate(DateTime date, ICurrency currency, decimal rate)
{
Currency = currency;
Date = date;
Rate = rate;
}
[XmlIgnore]
public string SrcName
{
get { return "CBR"; }
}
[XmlElement(ElementName = "RequestDate")]
public DateTime Date { get; set; }
[XmlIgnore]
public ICurrency Currency { get; set; }
[XmlElement(ElementName = "Direction")]
public string Direction
{
get { return "RUR=>" + CodeChar.Trim(); }
}
[XmlElement(ElementName = "RateValue")]
public decimal Rate { get; set; }
[XmlElement(ElementName = "RateBase")]
public decimal BaseRate
{
get { return Math.Round(Rate/Nominal, 4); }
}
[XmlElement(ElementName = "RateCross")]
public decimal CrossRate
{
get { return Math.Round(1.00M/BaseRate, 4); }
}
[XmlElement(ElementName = "CodeNum")]
public int CodeNum
{
get { return Currency.CodeNumIso; }
}
[XmlElement(ElementName = "CodeISO")]
public string CodeChar
{
get { return Currency.CodeCharIso; }
}
[XmlElement(ElementName = "CurrencyName")]
public string Name
{
get { return Currency.Name; }
}
[XmlElement(ElementName = "Nominal")]
public decimal Nominal
{
get { return Currency.Nominal; }
}
}
public static XDocument Serialize<T>(this T source)
{
var target = new XDocument();
var s = new XmlSerializer(typeof (T));
using (var writer = target.CreateWriter())
{
s.Serialize(writer, source);
writer.Close();
}
return target;
}
But, that I have:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfCbrRate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CbrRate>
<RequestDate>2011-09-05T18:49:55.1195696+04:00</RequestDate>
<RateValue>31.0539</RateValue>
</CbrRate>
...
How I can create correct xml, like this:
<ArrayOfRates>
<Rates>
<RequestDate></RequestDate>
<Direction></Direction>
<RateValue></RateValue>
<RateBase></RateBase>
...
First of all, .Net XmlSerializer will only serialize read/write properties (or fields). That's why only RequestDate and RateValue are serialized.
In order to achieve the XML structure you mentioned, you need to create a wrapper class as Roel said.
So, assuming you are serializing a List<CbrRate >, you will need to create a wrapper class for the list to have it serialized as you want it. Something like this:
[XmlRoot("root")]
public class ListOfRates
{
[XmlArray("ArrayOfRates")]
[XmlArrayItem("Rate")]
public List<CbrRate> Rates { get; set; }
}
this will produce the xml you want. Or you can play around with the attributes a little but if you don't want to have a root:
[XmlRoot("ArrayOfRates")]
public class ListOfRates
{
[XmlArrayItem("Rate")]
public List<CbrRate> Rates { get; set; }
}
the two attributes XmlArray and XmlArrayItem are key here. If you don't provide a name for the xml element, it will default to the property name.
I need to be able to define two nodes with the same name but completely different subnode structures. I didn't design this XML schema but for the time being I'm forced to use it as is. I realize it's a terrible abuse of everything that is XML but there you have it.
What I need it to look like:
<order>
<ItemType type="Clubs">
<Club num="1">
<ClubName>Some Name</ClubName>
<ClubChoice>Something Else</ClubChoice>
</Club>
</ItemType>
<ItemType type="Gift" val="MailGreeting">
<GiftName>MailGreeting</GiftName>
<GiftDescription></GiftDescription>
<GiftQuanity>1</GiftQuanity>
</ItemType
</order>
Of course it's far more complicated than but you get the gist.
I'm using XmlSerializer and would really like to avoid using XDocument but if that's what I need to do then so be it.
If your order contains properties and not a list you can tell the serializer to name the elements like this:
[XmlRoot("order")]
public class Order
{
private Whatever whateverInstance;
[XmlElement("ItemType")]
public Whatever WhateverInstance
{
get { return whateverInstance; }
set { whateverInstance = value; }
}
private Something somethingInstance;
[XmlElement("ItemType")]
public Something SomethingInstance
{
get { return somethingInstance; }
set { somethingInstance = value; }
}
}
If it's a list of things you could get to have a identical element name as well but you will get a redundant xsi:Type attribute:
[XmlRoot("order")]
public class Order
{
private ItemType[] itemTypes;
[XmlElement("ItemType")]
public ItemType[] ItemTypes
{
get { return itemTypes; }
set { itemTypes = value; }
}
}
[XmlInclude(typeof(Clubs))]
[XmlInclude(typeof(Gift))]
public abstract class ItemType
{
private string type = "None";
[XmlAttribute]
public string Type
{
get { return type; }
set { type = value; }
}
}
public class Clubs : ItemType
{
public Clubs()
{
Type = "Clubs";
}
private Club[] clubsArray;
[XmlElement("Club")]
public Club[] ClubsArray
{
get { return clubsArray; }
set { clubsArray = value; }
}
}
public class Club
{
private int num = 0;
[XmlAttribute("num")]
public int Num
{
get { return num; }
set { num = value; }
}
private string clubName = "";
public string ClubName
{
get { return clubName; }
set { clubName = value; }
}
private string clubChoice = "";
public string ClubChoice
{
get { return clubChoice; }
set { clubChoice = value; }
}
}
public class Gift : ItemType
{
public Gift()
{
Type = "Gift";
}
private string val = "";
[XmlAttribute("val")]
public string Val
{
get { return val; }
set { val = value; }
}
private string giftName = "";
public string GiftName
{
get { return giftName; }
set { giftName = value; }
}
private string giftDescription = "";
public string GiftDescription
{
get { return giftDescription; }
set { giftDescription = value; }
}
private int giftQuanity = 0;
public int GiftQuanity
{
get { return giftQuanity; }
set { giftQuanity = value; }
}
}
Test:
List<ItemType> list = new List<ItemType>();
list.Add(new Clubs() { ClubsArray = new Club[] { new Club() { Num = 0, ClubName = "Some Name", ClubChoice = "Something Else" } } });
list.Add(new Gift() { Val = "MailGreeting", GiftName = "MailGreeting", GiftDescription = "GiftDescription", GiftQuanity = 1});
Order order = new Order();
rder.ItemTypes = list.ToArray();
XmlSerializer serializer = new XmlSerializer(typeof(Order));
StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Stuff.xml");
serializer.Serialize(sw, order);
sw.Close();
Output:
<order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ItemType xsi:type="Clubs" Type="Clubs">
<Club num="0">
<ClubName>Some Name</ClubName>
<ClubChoice>Something Else</ClubChoice>
</Club>
</ItemType>
<ItemType xsi:type="Gift" Type="Gift" val="MailGreeting">
<GiftName>MailGreeting</GiftName>
<GiftDescription>GiftDescription</GiftDescription>
<GiftQuanity>1</GiftQuanity>
</ItemType>
</order>
I am having trouble with XML deserialization.
In a nutshell -
I have 2 classes:
SMSMessage
SMSSendingResponse
I call an API that takes a bunch of parameters (represented by SMSMessage class)
It returns an XML response.
The response looks like this:
<?xml version="1.0" encoding="utf-8"?>
<data>
<status>1</status>
<message>OK</message>
<results>
<result>
<account>12345</account>
<to>012345678</to>
<from>054321</from>
<message>Testing</message>
<flash></flash>
<replace></replace>
<report></report>
<concat></concat>
<id>f8d3eea1cbf6771a4bb02af3fb15253e</id>
</result>
</results>
</data>
Here is the SMSMessage class (with the xml serialization attributes so far)
using System.Xml.Serialization;
namespace XMLSerializationHelp
{
[XmlRoot("results")]
public class SMSMessage
{
public string To
{
get
{
return Result.To;
}
}
public string From
{
get
{
return Result.From;
}
}
public string Message
{
get
{
return Result.Message;
}
}
[XmlElement("result")]
public Result Result { get; set; }
}
}
Here is SMSMessageSendingResponse:
using System.Xml.Serialization;
namespace XMLSerializationHelp
{
[XmlRoot("data")]
public class SMSSendingResponse
{
//should come from the results/result/account element. in our example "12345"
public string AccountNumber
{
get
{
return SMSMessage.Result.AccountNumber;
}
}
//should come from the "status" xml element
[XmlElement("status")]
public string Status { get; set; }
//should come from the "message" xml element (in our example - "OK")
[XmlElement("message")]
public string Message { get; set; }
//should come from the "id" xml element (in our example - "f8d3eea1cbf6771a4bb02af3fb15253e")
public string ResponseID
{
get
{
return SMSMessage.Result.ResponseID;
}
}
//should be created from the results/result element - ignore flash, replace, report and concat elements for now.
[XmlElement("results")]
public SMSMessage SMSMessage { get; set; }
}
}
Here is the other class (Result) - I want to get rid of this, so only the 2 previously mentioned classes remain
using System.Xml.Serialization;
namespace XMLSerializationHelp
{
[XmlRoot("result")]
public class Result
{
[XmlElement("account")]
public string AccountNumber{ get; set; }
[XmlElement("to")]
public string To { get; set; }
[XmlElement("from")]
public string From { get; set; }
[XmlElement("message")]
public string Message { get; set; }
[XmlElement("id")]
public string ResponseID { get; set; }
}
}
I don't want SMSMessage to be aware of the SMSSendingResponse - as this will be handled by a different part of my application
I hope this helps. The XML structure implies the <result> element can occur more than once, so see if this helps you achieve what you need:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Xml;
namespace XMLSerializationHelp
{
class Program
{
static void Main(string[] args)
{
string strXML = #"<?xml version=""1.0"" encoding=""utf-8""?>
<data>
<status>1</status>
<message>OK</message>
<results>
<result>
<account>12345</account>
<to>012345678</to>
<from>054321</from>
<message>Testing</message>
<flash></flash>
<replace></replace>
<report></report>
<concat></concat>
<id>f8d3eea1cbf6771a4bb02af3fb15253e</id>
</result>
</results>
</data>";
XmlSerializer serializer = new XmlSerializer(typeof(SMSSendingResponse));
SMSSendingResponse obj = (SMSSendingResponse)serializer.Deserialize(new XmlTextReader(strXML, XmlNodeType.Document, null));
Console.WriteLine("Status: {0}", obj.Status);
Console.WriteLine("Message: {0}", obj.Message);
Console.WriteLine("Account Number: {0}", obj.AccountNumber);
Console.WriteLine("ResponseID: {0}", obj.ResponseID);
Console.WriteLine("To: {0}", obj.To);
Console.WriteLine("From: {0}", obj.From);
Console.WriteLine("ResultMessage: {0}", obj.ResultMessage);
Console.ReadLine();
}
}
[Serializable]
[XmlRoot("data")]
public class SMSSendingResponse
{
public SMSSendingResponse() {}
//should come from the "status" xml element
[XmlElement("status")]
public string Status { get; set; }
//should come from the "message" xml element (in our example - "OK")
[XmlElement("message")]
public string Message { get; set; }
//should come from the results/result/account element. in our example "12345"
[XmlIgnore()]
public string AccountNumber
{
get
{
Result r = FirstResult;
return (r != null) ? r.AccountNumber : null;
}
}
//should come from the "id" xml element (in our example - "f8d3eea1cbf6771a4bb02af3fb15253e")
[XmlIgnore()]
public string ResponseID
{
get
{
Result r = FirstResult;
return (r != null) ? r.ResponseID : null;
}
}
[XmlIgnore()]
public string To
{
get
{
Result r = FirstResult;
return (r != null) ? r.To : null;
}
}
[XmlIgnore()]
public string From
{
get
{
Result r = FirstResult;
return (r != null) ? r.From : null;
}
}
[XmlIgnore()]
public string ResultMessage
{
get
{
Result r = FirstResult;
return (r != null) ? r.Message : null;
}
}
[XmlArray("results"), XmlArrayItem("result", typeof(Result))]
public List<Result> Results
{
get { return (_Results); }
set { _Results = value; }
} private List<Result> _Results = new List<Result>();
[XmlIgnore()]
public Result FirstResult
{
get
{
return (_Results != null && _Results.Count > 0) ? _Results[0] : null;
}
}
}
[XmlType(TypeName = "result"), Serializable]
public class Result
{
public Result() {}
[XmlElement("account")]
public string AccountNumber { get; set; }
[XmlElement("to")]
public string To { get; set; }
[XmlElement("from")]
public string From { get; set; }
[XmlElement("message")]
public string Message { get; set; }
[XmlElement("id")]
public string ResponseID { get; set; }
}
}