Deserialize xml does not pick up element - c#

I am trying to deserialize some xml. Here it is:
<FooBars xmlns="http://foos">
<Id1 xmlns="http://bars">2</Id1>
<Id2 xmlns="http://bars">7</Id2>
<Info xmlns="http://bars">
<Data>
<Field1>text1</Field1>
<Field2>text2</Field2>
<Field3>text3</Field3>
</Data>
<Data>
<Field1>text5</Field1>
<Field2>text6</Field2>
<Field3>text7</Field3>
</Data>
</Info>
</FooBars>
I tried this:
var myData = (FooBars)serializer.Deserialize(foobars.CreateReader());
...
[XmlRoot(ElementName = "FooBars", Namespace = "http://foos")]
public class FooBars
{
[XmlElement(ElementName = "Id1", Namespace = "http://bars")]
public string Id1 { get; set; }
[XmlElement(ElementName = "Id2", Namespace = "http://bars")]
public string Id2 { get; set; }
[XmlElement(ElementName = "Info", Namespace = "http://bars")]
public List<Data> Info { get; set; }
}
public class Data
{
[XmlElement(ElementName = "Field1")]
public string Field1 { get; set; }
[XmlElement(ElementName = "Field2")]
public string Field2 { get; set; }
}
But it looks like the Data class is not considered part of the xml, since it is not able to read it. I am getting all the other elements (ids) but not the things defined in Data.
Where am I wrong?

Presuming missing </Info> tag is a typo, All you need is XmlArray and XmlArrayItem
[XmlRoot(ElementName = "FooBars", Namespace = "http://foos")]
public class FooBars
{
[XmlElement(ElementName = "Id1", Namespace = "http://bars")]
public string Id1 { get; set; }
[XmlElement(ElementName = "Id2", Namespace = "http://bars")]
public string Id2 { get; set; }
[XmlArray(ElementName = "Info", Namespace = "http://bars"), XmlArrayItem("Data")] //<--
public List<Data> Info { get; set; }
}

The XML is missing a closing tag for Info. Also, you need to defined the Field3 property in the Data class and add the namespace 'http://bars' to it.

If your xml is missing the info closing tag, meant to contain the Data elements then your classes should look something like:
[XmlRoot(ElementName = "FooBars", Namespace = "http://foos")]
public class FooBars
{
[XmlElement(ElementName = "Id1", Namespace = "http://bars")]
public string Id1 { get; set; }
[XmlElement(ElementName = "Id2", Namespace = "http://bars")]
public string Id2 { get; set; }
[XmlElement(ElementName = "Info", Namespace = "http://bars")]
public Info Information { get;set; }
}
public class Info {
[XmlElement(ElementName = "Data", Namespace = "")]
public Info[] Info { get; set; }
}
public class Data
{
[XmlElement(ElementName = "Field1")]
public string Field1 { get; set; }
[XmlElement(ElementName = "Field2")]
public string Field2 { get; set; }
}
Notice how in your xml the info object basically contains all the data, not the FooBars like you designed the classes.

via LinqPad - you can see the Field properties are null in the myData.Info property, and that is your problem, right? UPDATED:
void Main()
{
string xmlString;
string path = #"C:\Temp\exampleXmlSO.xml";
using (StreamReader streamReader = File.OpenText(path))
{
xmlString = streamReader.ReadToEnd();
}
XmlSerializer serializer = new XmlSerializer(typeof(FooBars));
using (StringReader stringReader = new StringReader(xmlString))
{
var myData = (FooBars)serializer.Deserialize(stringReader);
Console.WriteLine(myData);
}
}
[XmlRoot(ElementName = "FooBars", Namespace = "http://foos")]
public class FooBars
{
[XmlElement(ElementName = "Id1", Namespace = "http://bars")]
public string Id1 { get; set; }
[XmlElement(ElementName = "Id2", Namespace = "http://bars")]
public string Id2 { get; set; }
[XmlArray(ElementName = "Info", Namespace = "http://bars"), XmlArrayItem("Data")] //<--
public List<Data> Info { get; set; }
}
[Serializable]
public class Data
{
[XmlElement(ElementName = "Field1")]
public string Field1 { get; set; }
[XmlElement(ElementName = "Field2")]
public string Field2 { get; set; }
[XmlIgnore]
public string Field3 { get; set; }
}

Related

Deserialize XML with list of elements where some are xsi:nil=“true”

When I deserialize the XML below, from a third-party, my objects are always null.
XML
<?xml version="1.0"?>
<OrderImport xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Reply i:nil="true">
</Reply>
<ReplyStatus i:nil="true">
<DebugInfo>
</DebugInfo>
<PerformanceLogInfo>
</PerformanceLogInfo>
</ReplyStatus>
<Reply>
<OrderNumber>4063286</OrderNumber>
</Reply>
<ReplyStatus>
<Result>0</Result>
<Message>
</Message>
</ReplyStatus>
</OrderImport>
C# Class
[XmlRoot(ElementName = "OrderImport")]
public class OrderImport
{
[XmlElement(ElementName = "Reply")]
public List<Reply> Reply { get; set; }
[XmlElement(ElementName = "ReplyStatus")]
public List<ReplyStatus> ReplyStatus { get; set; }
[XmlAttribute(AttributeName = "i", Namespace = "http://www.w3.org/2000/xmlns/")]
public string I { get; set; }
}
[XmlRoot(ElementName= "Reply")]
public class Reply
{
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
[XmlElement(ElementName = "OrderNumber")]
public string OrderNumber { get; set; }
}
[XmlRoot(ElementName = "ReplyStatus")]
public class ReplyStatus
{
[XmlElement(ElementName = "DebugInfo")]
public string DebugInfo { get; set; }
[XmlElement(ElementName = "PerformanceLogInfo")]
public string PerformanceLogInfo { get; set; }
[XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Nil { get; set; }
[XmlElement(ElementName = "Result")]
public string Result { get; set; }
[XmlElement(ElementName = "Message")]
public string Message { get; set; }
}
I believe the problem has to do with the first occurrence of the objects Reply and ReplyStatus being null.
I'm trying to deserialize like so
httpResponseMessage.Content.ReadAsAsync<OrderImport>().Result;
However, I've found that if I deserialize like this it works just fine
stringres = httpResponseMessage.Content.ReadAsStringAsync().Result;
using (var stringreader = new StringReader(stringres))
{
var result = (OrderImport)xmlSerializer.Deserialize(stringreader);
}

Populate Observable collection from XML file in project (WPF)

I Have XML file in my project
Here is it
<?xml version="1.0"?>
<catalog>
<car id="1">
<model>Scoda Fabia</model>
<year>2011</year>
<producer>Folkwagen</producer>
<price>6000</price>
<owner>Bil Johnson</owner>
<tel>+5810456455456</tel>
<mileage>670000</mileage>
<registered>USA</registered>
<image>Fabia1.JPG</image>
</car>
<car id="2">
<model>Huindai Getz</model>
<year>2008</year>
<producer>Huindai</producer>
<price>5000</price>
<owner>Dimitrious Gregorakis</owner>
<tel>+5810456445456</tel>
<mileage>120000</mileage>
<registered>USA</registered>
<image>hyundai_getz2.jpg</image>
</car>
<car id="3">
<model>Huindai i108</model>
<year>2014</year>
<producer>Huindai</producer>
<price>15000</price>
<owner>Dex Dexter</owner>
<tel>+5815556445456</tel>
<mileage>30000</mileage>
<registered>Canada</registered>
<image>hyundaii108.jpg</image>
</car>
<car id="4">
<model>Aveo</model>
<year>2000</year>
<producer>Shevrole</producer>
<price>3500</price>
<owner>Ivan Ivanov</owner>
<tel>+5815556445477</tel>
<mileage>300000</mileage>
<registered>Mexico</registered>
<image>aveo.jpg</image>
</car>
</catalog>
I created a class from it, here is code for class
[XmlRoot(ElementName = "car")]
public class Car
{
[XmlElement(ElementName = "model")]
public string Model { get; set; }
[XmlElement(ElementName = "year")]
public string Year { get; set; }
[XmlElement(ElementName = "producer")]
public string Producer { get; set; }
[XmlElement(ElementName = "price")]
public string Price { get; set; }
[XmlElement(ElementName = "owner")]
public string Owner { get; set; }
[XmlElement(ElementName = "tel")]
public string Tel { get; set; }
[XmlElement(ElementName = "mileage")]
public string Mileage { get; set; }
[XmlElement(ElementName = "registered")]
public string Registered { get; set; }
[XmlElement(ElementName = "image")]
public string Image { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
}
[XmlRoot(ElementName = "catalog")]
public class Catalog
{
[XmlElement(ElementName = "car")]
public List<Car> Car { get; set; }
}
And Created ViewModel for it, where I defined observable collection anв define a method to fill it with data from XML
public class CarViewModel
{
public ObservableCollection<List<Car>> car { get; set; }
public void LoadCars()
{
Car = new ObservableCollection<List<Car>>();
var path = #"xml\CarsDatabase.xml";
using (TextReader reader = new StreamReader(path))
{
XmlSerializer serializer = new XmlSerializer(typeof(Catalog));
return (Catalog)serializer.Deserialize(reader);
}
}
}
In method LoadCars I need to fill car observable collections with data in my file, that is inside of the project.
How I can do this correctly?
Thank's for help.
UPDATE
I try to use this method
public void LoadCars()
{
Car = new ObservableCollection<List<Car>>();
var path = #"xml\CarsDatabase.xml";
using (TextReader reader = new StreamReader(path))
{
XmlSerializer serializer = new XmlSerializer(typeof(Catalog));
return (Catalog)serializer.Deserialize(reader);
}
}
But now I have error
Severity Code Description Project File Line Suppression State
Error CS0127 Since 'CarViewModel.LoadCars()' returns void, a return keyword must not be followed by an object expression DaxxTest C:\Users\nemes\Source\Repos\daxx_test\DaxxTest\DaxxTest\ViewModels\CarViewModel.cs 25 Active
Change
public ObservableCollection<List<Car>> car { get; set; }
to
public ObservableCollection<Car> car { get; set; }
And use XmlSerializer to serialize your xml information. Check bellow code for an example:
public ObservableCollection<Car> cars { get; set; }
public void LoadCars()
{
XmlSerializer serializer = new XmlSerializer(typeof(Catalog));
StreamReader reader = new StreamReader("CarsDatabase.xml");
var catalog = (Catalog)serializer.Deserialize(reader);
cars = new ObservableCollection<Car>(catalog.Car);
reader.Close();
}
[Serializable()]
public class Car
{
[XmlElement(ElementName = "model")]
public string Model { get; set; }
[XmlElement(ElementName = "year")]
public string Year { get; set; }
[XmlElement(ElementName = "producer")]
public string Producer { get; set; }
[XmlElement(ElementName = "price")]
public string Price { get; set; }
[XmlElement(ElementName = "owner")]
public string Owner { get; set; }
[XmlElement(ElementName = "tel")]
public string Tel { get; set; }
[XmlElement(ElementName = "mileage")]
public string Mileage { get; set; }
[XmlElement(ElementName = "registered")]
public string Registered { get; set; }
[XmlElement(ElementName = "image")]
public string Image { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
}
[Serializable()]
[XmlRootAttribute("catalog", Namespace = "", IsNullable = false)]
public class Catalog
{
[XmlElement(ElementName = "car")]
public List<Car> Car { get; set; }
}

How to map C# object to SQLite database table?

I have the following SQLite table
And I have the following C# classes:
[XmlRoot(ElementName = "articlessql", Namespace = "http://tempuri.org/DataSet1.xsd")]
public class Article
{
[XmlElement(ElementName = "id", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string Id { get; set; }
[XmlElement(ElementName = "name", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string Name { get; set; }
[XmlElement(ElementName = "quantity", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string Quantity { get; set; }
[XmlElement(ElementName = "sell_price", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string SellPrice { get; set; }
[XmlElement(ElementName = "sellid", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string SellId { get; set; }
[XmlElement(ElementName = "whole_price", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string WholePrice { get; set; }
[XmlElement(ElementName = "group", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string Group { get; set; }
[XmlElement(ElementName = "barcode", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string Barcode { get; set; }
[XmlElement(ElementName = "measure", Namespace = "http://tempuri.org/DataSet1.xsd")]
public string Measure { get; set; }
}
[XmlRoot(ElementName = "DataSet1", Namespace = "http://tempuri.org/DataSet1.xsd")]
public class Articles
{
[XmlElement(ElementName = "articlessql", Namespace = "http://tempuri.org/DataSet1.xsd")]
public List<Article> AllArticles { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
}
I get list of articles like that:
XmlSerializer deserializer = new XmlSerializer(typeof(Articles));
TextReader textReader = new StreamReader(xmlFilePath);
Articles articles = new Articles();
articles = (Articles)deserializer.Deserialize(textReader);
textReader.Close();
But when I try to insert the list of articles in the table articles like that:
using (var connection = new SQLiteConnection(System.IO.Path.Combine(apkFolder, "MobileSell.db")))
{
connection.InsertAll(articles.AllArticles);
}
It throws exception:
SQLite.SQLiteException: no such table: Article at SQLite.SQLite3.Prepare2
My question is how can I make the program understand that Article object must be a single row in table articles
did you read SQLite specification?
SQLite has attributes like [Column] and [Table] attributes. You should use those. Like this:
[Table("ContactInfo")] // SQLite attribute
[DataContract(Name = "ContactInfo", Namespace = "")]
public sealed class ContactInfo : DatabaseTableBase
{
/// <summary>
/// Unique Id of the codebook.
/// </summary>
[PrimaryKey] // SQLite attribute
[AutoIncrement] // SQLite attribute
[Column("UniqueId")] // SQLite attribute
[IgnoreDataMember]
public override long UniqueId { get; set; }
[Column("ClaimId")] // SQLite attribute
[NotNull] // SQLite attribute
public long ClaimId { get; set; }
[Column("ContactType")] // SQLite attribute
[NotNull] // SQLite attribute
public ContactTypes ContactType { get; set; }
public ContactInfo()
{
}
}
In your case, you will be annotating with attributes your class Article
Hope it helps.

Reading data from XML file in C#

I am attempting to read data from an XML file in C# (for Windows Phone).
I return the following XML file:
private async void GetCoords2()
{
string requestURI = "https://maps.googleapis.com/maps/api/geocode/xml?address=Donegal%20Town&key=XXX";
HttpWebRequest request = HttpWebRequest.Create(requestURI) as HttpWebRequest;
WebResponse response = await request.GetResponseAsync();
using (var reader = new StreamReader(response.GetResponseStream()))
{
responseContent = reader.ReadToEnd();
// Do anything with you content. Convert it to xml, json or anything.
ParseContent();
}
}
I am attempting to retrieve the first instance of latitude and longtitude from the XML file, which is available here: https://maps.googleapis.com/maps/api/geocode/xml?address=Donegal%20Town&key=XXX
I have followed several samples from online, and previous projects I have worked on, but none seem to be working.
How can I retrieve the first instance of lat and lon?
Thanks.
Edit: had to remove key from URL, posted screenshot of image instead.
UPDATE: The code I currently have.
void ParseContent()
{
XmlReader xmlReader = XmlReader.Create(responseContent);
List<string> aTitle = new List<string>();
// Add as many as attributes you have in your "stop" element
XmlReader reader = XmlReader.Create(responseContent);
reader.ReadToDescendant("location");
while (reader.Read())
{
reader.MoveToFirstAttribute();
reader.ReadToFollowing("lat");
string latX = reader.ReadElementContentAsString();
reader.ReadToFollowing("lng");
string lngX = reader.ReadElementContentAsString();
//reader.ReadToFollowing("Subcategory");
//string subcategory = reader.ReadElementContentAsString();
//reader.ReadToFollowing("Favourited");
//Boolean favourited = Boolean.Parse(reader.ReadElementContentAsString());
//basketxml.Add(new Pets(name, category, subcategory, description, dob, stock, price, image, id, favourited));
MessageBox.Show(latX + " / " + lngX);
}
}
FOUND ANSWER HERE:
http://www.superstarcoders.com/blogs/posts/geocoding-in-c-sharp-using-google-maps.aspx
Try something like this....
Usings...
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
Classes.... .(created from your XML using http://xmltocsharp.azurewebsites.net/)
[XmlRoot(ElementName = "address_component")]
public class Address_component
{
[XmlElement(ElementName = "long_name")]
public string Long_name { get; set; }
[XmlElement(ElementName = "short_name")]
public string Short_name { get; set; }
[XmlElement(ElementName = "type")]
public List<string> Type { get; set; }
}
[XmlRoot(ElementName = "location")]
public class Location
{
[XmlElement(ElementName = "lat")]
public string Lat { get; set; }
[XmlElement(ElementName = "lng")]
public string Lng { get; set; }
}
[XmlRoot(ElementName = "southwest")]
public class Southwest
{
[XmlElement(ElementName = "lat")]
public string Lat { get; set; }
[XmlElement(ElementName = "lng")]
public string Lng { get; set; }
}
[XmlRoot(ElementName = "northeast")]
public class Northeast
{
[XmlElement(ElementName = "lat")]
public string Lat { get; set; }
[XmlElement(ElementName = "lng")]
public string Lng { get; set; }
}
[XmlRoot(ElementName = "viewport")]
public class Viewport
{
[XmlElement(ElementName = "southwest")]
public Southwest Southwest { get; set; }
[XmlElement(ElementName = "northeast")]
public Northeast Northeast { get; set; }
}
[XmlRoot(ElementName = "geometry")]
public class Geometry
{
[XmlElement(ElementName = "location")]
public Location Location { get; set; }
[XmlElement(ElementName = "location_type")]
public string Location_type { get; set; }
[XmlElement(ElementName = "viewport")]
public Viewport Viewport { get; set; }
[XmlElement(ElementName = "bounds")]
public Bounds Bounds { get; set; }
}
[XmlRoot(ElementName = "result")]
public class Result
{
[XmlElement(ElementName = "type")]
public List<string> Type { get; set; }
[XmlElement(ElementName = "formatted_address")]
public string Formatted_address { get; set; }
[XmlElement(ElementName = "address_component")]
public List<Address_component> Address_component { get; set; }
[XmlElement(ElementName = "geometry")]
public Geometry Geometry { get; set; }
[XmlElement(ElementName = "place_id")]
public string Place_id { get; set; }
}
[XmlRoot(ElementName = "bounds")]
public class Bounds
{
[XmlElement(ElementName = "southwest")]
public Southwest Southwest { get; set; }
[XmlElement(ElementName = "northeast")]
public Northeast Northeast { get; set; }
}
[XmlRoot(ElementName = "GeocodeResponse")]
public class GeocodeResponse
{
[XmlElement(ElementName = "status")]
public string Status { get; set; }
[XmlElement(ElementName = "result")]
public List<Result> Result { get; set; }
}
Code...
try
{
string query1 = string.Format("https://maps.googleapis.com/maps/api/geocode/xml?address=Donegal%20Town&key=<Your Key>");
XmlDocument GeocodeResponse = new XmlDocument();
GeocodeResponse.Load(query1);
string XMLGeocodeResponse = GeocodeResponse.InnerXml.ToString();
byte[] BUFGeocodeResponse = ASCIIEncoding.UTF8.GetBytes(XMLGeocodeResponse);
MemoryStream ms1 = new MemoryStream(BUFGeocodeResponse);
XmlSerializer DeserializerPlaces = new XmlSerializer(typeof(GeocodeResponse), new XmlRootAttribute("GeocodeResponse"));
using (XmlReader reader = new XmlTextReader(ms1))
{
GeocodeResponse dezerializedXML = (GeocodeResponse)DeserializerPlaces.Deserialize(reader);
Location LatLng = dezerializedXML.Result[0].Geometry.Location;
}// Put a break-point here, then mouse-over LatLng and you should have you values
}
catch (System.Exception)
{
throw;
}
This will deserialize the whole thing into a single object, then you can select elements you need (as you can see with 'LatLng' above has the two coordinates you wanted to extract)...

.NET Xml deserialization, issue/error with xsi:type attribute

VS2008, .NET Framework 3.5
We're utilizing the WebEx Xml API. Here's a sample Xml response from their web service that I'm trying to deserialize into .NET classes.
<?xml version="1.0" encoding="UTF-8"?>
<serv:message xmlns:serv="http://www.webex.com/schemas/2002/06/service" xmlns:com="http://www.webex.com/schemas/2002/06/common"
xmlns:event="http://www.webex.com/schemas/2002/06/service/event"><serv:header><serv:response><serv:result>SUCCESS</serv:result><serv:gsbStatus>PRIMARY</s
erv:gsbStatus></serv:response></serv:header>
<serv:body>
<serv:bodyContent xsi:type="event:lstsummaryEventResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<event:matchingRecords>
<serv:total>2</serv:total>
<serv:returned>2</serv:returned>
<serv:startFrom>1</serv:startFrom>
</event:matchingRecords>
<event:event>
<event:sessionKey>999999</event:sessionKey>
<event:sessionName>Test Event 1</event:sessionName>
<event:sessionType>129</event:sessionType>
<event:hostWebExID>SomeName</event:hostWebExID>
<event:startDate>03/28/2012 14:30:00</event:startDate>
<event:endDate>03/28/2012 14:45:00</event:endDate>
<event:timeZoneID>11</event:timeZoneID>
<event:duration>15</event:duration>
<event:description></event:description>
<event:status>NOT_INPROGRESS</event:status>
<event:panelists></event:panelists>
<event:listStatus>PUBLIC</event:listStatus>
</event:event>
</serv:bodyContent>
</serv:body>
</serv:message>
Here's the class that we're deserializing into:
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Collections.Generic;
namespace Masonite.MTier.WebEx
{
[Serializable()]
[XmlRoot("message", Namespace = "http://www.webex.com/schemas/2002/06/service")]
public class lstsummaryEventResponsexx
{
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
public lstsummaryEventResponsexx()
{
xmlns.Add("serv", "http://www.webex.com/schemas/2002/06/service");
xmlns.Add("com", "http://www.webex.com/schemas/2002/06/common");
xmlns.Add("event", "http://www.webex.com/schemas/2002/06/service/event");
}
[XmlElement(ElementName = "header")]
public Header header { get; set; }
[XmlElement(ElementName = "body")]
public Body body { get; set; }
[Serializable()]
[XmlRoot("header")]
public class Header
{
[XmlElement(ElementName = "response")]
public Response response { get; set; }
}
[Serializable()]
[XmlRoot("body")]
[XmlInclude(typeof(lstsummaryEventResponse))]
public class Body
{
[XmlElement(ElementName = "bodyContent", Form = XmlSchemaForm.Qualified)]
public BodyContent bodyContent { get; set; }
}
[Serializable()]
public class lstsummaryEventResponse
{
}
[Serializable()]
[XmlRoot("response")]
public class Response
{
[XmlElement(ElementName = "result")]
public string result { get; set; }
[XmlElement(ElementName = "reason")]
public string reason { get; set; }
[XmlElement(ElementName = "gsbStatus")]
public string gsbStatus { get; set; }
[XmlElement(ElementName = "exceptionID")]
public string exceptionID { get; set; }
}
[Serializable()]
[XmlRoot("bodyContent")]
public class BodyContent
{
[XmlElement(ElementName = "matchingRecords", Namespace = "http://www.webex.com/schemas/2002/06/service/event")]
public MatchingRecords matchingRecords { get; set; }
[XmlElement(ElementName = "event", Namespace = "http://www.webex.com/schemas/2002/06/service/event")]
public List<EventSummary> events { get; set; }
}
[Serializable()]
[XmlRoot("matchingRecords")]
public class MatchingRecords
{
[XmlElement(ElementName = "total", Namespace = "http://www.webex.com/schemas/2002/06/service")]
public int total { get; set; }
[XmlElement(ElementName = "returned", Namespace = "http://www.webex.com/schemas/2002/06/service")]
public int returned { get; set; }
[XmlElement(ElementName = "startFrom", Namespace = "http://www.webex.com/schemas/2002/06/service")]
public int startFrom { get; set; }
}
[Serializable()]
[XmlRoot("event")]
public class EventSummary
{
[XmlElement(ElementName = "sessionKey")]
public long sessionKey { get; set; }
[XmlElement(ElementName = "sessionName")]
public string sessionName { get; set; }
[XmlElement(ElementName = "sessionType")]
public int sessionType { get; set; }
[XmlElement(ElementName = "hostWebExID")]
public string hostWebExID { get; set; }
[XmlElement(ElementName = "startDate")]
public string startDate { get; set; }
[XmlElement(ElementName = "endDate")]
public string endDate { get; set; }
[XmlElement(ElementName = "timeZoneID")]
public int timeZoneID { get; set; }
[XmlElement(ElementName = "duration")]
public int duration { get; set; }
[XmlElement(ElementName = "description")]
public string description { get; set; }
[XmlElement(ElementName = "status")]
public string status { get; set; }
[XmlElement(ElementName = "panelists")]
public string panelists { get; set; }
[XmlElement(ElementName = "listStatus")]
public listingType listStatus { get; set; }
}
}
}
The error I'm receiving:
The specified type was not recognized: name='lstsummaryEventResponse', namespace='http://www.webex.com/schemas/2002/06/service/event', at <bodyContent xmlns='http://www.webex.com/schemas/2002/06/service'>
I'm not sure how to provide the type lstsummaryEventResponse for the Deserialize method. I added another serializable class to my class above using that name, but get the same error. Any thoughts?
BodyContent can have the type event:lstsummaryEventResponse - so you have to declare the corresponding class, and then decorate the declaration of BodyContent as follows:
[Serializable()]
[XmlRoot("bodyContent")]
[XmlInclude("lstsummaryEventResponse")]
public class BodyContent {
}
Having said that, creating C# class with a serialization corresponding to some arbitrary XML is pretty tricky, I am not sure it is right approach

Categories