Deserializing XML from String

Try this: string xml = “<StatusDocumentItem xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”><DataUrl/><LastUpdated>2013-02-01T12:35:29.9517061Z</LastUpdated><Message>Job put in queue</Message><State>0</State><StateName>Waiting to be processed</StateName></StatusDocumentItem>”; var serializer = new XmlSerializer(typeof(StatusDocumentItem)); StatusDocumentItem result; using (TextReader reader = new StringReader(xml)) { result = (StatusDocumentItem)serializer.Deserialize(reader); } Console.WriteLine(result.Message); Console.ReadKey(); Does it show “Job put in queue”?

using XmlArrayItem attribute without XmlArray on Serializable C# class

The following should serialize properly the way you want. The clue being [XmlElement(“credentials”)] on the list. I did this by taking your xml, generating a schema (xsd) from it in Visual Studio. Then running xsd.exe on the schema to generate a class. (And some small edits) public class CredentialsSection { public string Username { get; … Read more

Unable to generate a temporary class (result=1). error CS0030: Cannot convert type ‘Type[]’ to ‘Type’?

You need to change the type of a member variable in the serialized class. For example if its raising an error like: Unable to generate a temporary class (result=1). error CS0030: Cannot convert type ‘Data[]’ to ‘Data’. I ran a search on the Data type name in the generated file, and I found this: [System.Xml.Serialization.XmlArrayItemAttribute(“Data”, … Read more

How to deserialize xml to object [duplicate]

Your classes should look like this [XmlRoot(“StepList”)] public class StepList { [XmlElement(“Step”)] public List<Step> Steps { get; set; } } public class Step { [XmlElement(“Name”)] public string Name { get; set; } [XmlElement(“Desc”)] public string Desc { get; set; } } Here is my testcode. string testData = @”<StepList> <Step> <Name>Name1</Name> <Desc>Desc1</Desc> </Step> <Step> <Name>Name2</Name> … Read more

Is it possible to deserialize XML into List?

You can encapsulate the list trivially: using System; using System.Collections.Generic; using System.Xml.Serialization; [XmlRoot(“user_list”)] public class UserList { public UserList() {Items = new List<User>();} [XmlElement(“user”)] public List<User> Items {get;set;} } public class User { [XmlElement(“id”)] public Int32 Id { get; set; } [XmlElement(“name”)] public String Name { get; set; } } static class Program { static … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)