.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Sgraph Infotech
Imran Ghani
Post New Web Links

How to deserialize XML?

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :WPF
 

Hi,

 I have tried to read elements from XML based on the XMLNODES class in MSDN.

But at my office all prefers to deserialize xml to class and then get the elements.

Whats the best practise to work with XML file?




View Complete Post


More Related Resource Links

JSON Deserialize into Entity Framework Object and setting the DataMemberAttribute "Name="

  

Hi,

 

I'm in the process of deserializing a JSON object into an Entity Framework object.  The property names in the JSON do not match up totally with the property names in the Entity Framework Objects. What I'd like to do is set "Name=" on the  "DataContractAttribute" for the table and the "DataMemberAttribute" for the properties in the Designer.cs file.  I tried setting these in the Designer.cs file manually just to see if it would work - which it did (using JSON.Net) but of course when I went into the .edmx designer I lost all my changes.  Is there a way to do this?

 

Thanks in advance


The formatter threw an exception while trying to deserialize the message

  
Hi I got this error when programming in C# 2008 The formatter threw an exception when trying to deserialize the message: Error while trying to deserialize parameter http://tempuri.org/:GetListSitesResponse. The InnerException message was' Error on line 1, position 314. The item 'http://tempuri.org/:anyType' contains data data contract 'http://tempuri.org/:Site'. The deserializer has no knowledge of any type that is assigned to this contract. Add the type corresponding to 'Site' to the list of known types (eg, using the attribute KnownTypeAttribute or adding it to the list of known types passed to DataContractSerializer). '. See InnerException for more information. This happen in my button_click event (this is a project on C# 2008 express windows form application) private void button1_Click(object sender, EventArgs e)         {             SiteDevelopmentReference.Service1SoapClient sd = new SiteDevelopmentReference.Service1SoapClient();             listBox1.Items.AddRange(sd.GetListSites().ToArray());                            } I have a service reference from another project

Deserialize JSON object in C#

  
Hi, I am new to JSON and one of my service is returning JSON object as a string to my application. I need to Deserialize JSON object in C#. My JSON string is in the current format. string str = "{\"candidates\":[{\"address\":\"1580 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.42054,\"y\":37.7745960000001},\"score\":40,\"attributes\":{}},{\"address\":\"1576 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.420355,\"y\":37.7747030000001},\"score\":40,\"attributes\":{}}]}"; Can anyone please help me how to get all the address, locations, score and attributes from the above string. Thankyou, Ravi.

How could I deserialize a object which is serialized in JAVA??

  
When I try to do it with the code below. FileStream fileStream = new FileStream( "C:\\apps\\user.tmp", FileMode.Open, FileAccess.Read, FileShare.Read);     BinaryFormatter bf=new BinaryFormatter();     pd = (PianoData)bf.Deserialize(fileStream);     System.Console.WriteLine();     fileStream.Close(); Exception occurred as I had excepted. "The input stream is not a valid binary format."   I wonder if I can do it by another way

Serialize / DeSerialize XElement objecs using BinaryFormatter.

  
Hi, I'm having some business objects which contains XElement properties. I have some offline framework which serialize / deserialize using binary formatter. I'm getting the error "Type 'System.Xml.Linq.XElement' in Assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable." when i try to serialize the xelement object I'm getting the XElement serializer error. We are bit too far with design and need to find some work around to solve this issue. The following program should give you the same error behavior. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace XElementBinaryformatter {     public partial class Form1 : Form     {         private BinaryFormatter formatter = new BinaryFormatter();         public Form1()         {             InitializeComponent();         }         private void btnSerialize_Clic

Deserialize xml elements with attributes

  
Hi. How can I deserialize xml elements with attributes to a simple class using XmlSerializer ? Xml contains list of elements as so.     <elementGroups> <element unit="lbs">140</element> <element unit="kts">3040</element> <element unit="m">1003</element> </elementGroups>   The Element class should by like this.     public class Element { [ ????("value")] public decimal Value{ get; set; } [XmlAttribute("unit")] public string Unit{ get; set; } }   is there any elegant way to do this ?  thanks..    

Serialize / DeSerialize XElement objecs using BinaryFormatter.

  
Hi, I'm having some business objects which contains XElement properties. I have some offline framework which serialize / deserialize using binary formatter. I'm getting the error "Type 'System.Xml.Linq.XElement' in Assembly 'System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable." when i try to serialize the xelement object I'm getting the XElement serializer error. We are bit too far with design and need to find some work around to solve this issue. The following program should give you the same error behavior. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace XElementBinaryformatter {     public partial class Form1 : Form     {         private BinaryFormatter formatter = new BinaryFormatter();         public Form1()         {             InitializeComponent();         }         private void btnSerialize_Clic

Sharepoint Designer issue "could not deserialize object"?

  
Hi there, I'm relatively new to Sharepoint in general but I've got an install of Sharepoint Foundation and I'm working my way through the book "Sharepoint 2010 Development." At any rate, I'm trying to create a workflow in Visio 2010 and then export that workflow into Sharepoint Designer 2010. However, when I try to import the .vwi file into Designer, I get a "Could not deserialize object. The type 'Microsoft.Office.Workflow.Actions.ApprovalTaskProcess' could not be resolved." This, of course, is because in Visio I have a Start Approval Process object.  Is this particular workflow item not available for Sharepoint Foundation? Does anyone have any idea why I'm getting this error? Any feedback is appreciated. Thanks, Jearod

Can serialize but not deserialize class containing an xs:list attribute using XmlSerializer

  
I have a simple serializable class along the lines of: [Serializable] [XmlType] public class MyClass { [XmlAttribute("values")] public int[] Values { get; set; } } If I create an instance of this class with Values set to an empty collection the XmlSerializer class produces this output as expected: <?xml version="1.0" encoding="utf-16" ?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" values="" /> However, deserializing this exact output throws a System.FormatException: Input string was not in a correct format. Shouldn't the XmlSerializer be able to deserialize this, since it produced the xml string in the first place?

Re-signed my assembly, now I cannot deserialize objects saved before

  
I have a strange situation about object deserialization. My assemblies all had strong name but signed with different key pair file - I did not realize it is better to have all assemblies signed with the same key pair file before. And now I need to use one single key pair file to resign all assemblies for some other purpose. But After I did that, my program cannot deserialize objects saved by previous version of the assemblies anymore. Use XML object as example, In the XML file, the object is saved with this kind of information, <MyObject version="1" referenceType="MyObject, Assembly1, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f89a7ef07260c910"> <.... omited ... > </MyObject> The problem is that, the Assembly1 is resigned and the public key token of the running assembly does not match the token in the xml file. The same problem happens in my binary objects. Any gurus have some idea to deserialize objects after I resigned the assemblies? My program saved hundreds of objects, I hope there is some solution which will work with all of those objects.    

Timer job intiation error: SharePoint cannot deserialize an object of type

  
Hi All, when i run a timer job (One-Time timer) it has added it to Timer Job definitions in the Central Administration. I have checked the Log file in 12 hive and found the following error..... "SharePoint cannot deserialize an object of type xyz.xyzJob, xyzTimer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<token> on this machine. This typically occurs because the assembly containing this type is not installed on this machine. In this case, this message can be safely ignored. Otherwise, the assembly needs to be installed on this machine in a location that can be discovered by the .NET Framework." The above error says that the assembly is not added.... but it has been already added to the GAC. Can anyone guide me about the issue and how to resolve that........?

Help!!! WCF:: The formatter threw an exception while trying to deserialize the message

  
I have[ServiceContract]    public interface IBusiness    {        [OperationContract]        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]        bool UpdateLanguage(int languageId, string name, string code);    }public class Business:IBusiness    {        public bool UpdateLanguage(int languageId, string name, string code)        {           //update to database        }    }Add client:$.ajax({ type: "POST", url: "/Services/Business.svc/UpdateLanguage", data: "{'languageId':'" + languageId + "', " + "'name':'" + name + "'," + "'code':'" + code + "'}", contentType: "application/json; charset=utf-8", dataType: "json", processdata: true, success: function (response) { //rebind data here!

deserialize json string using javascript serializer problem

  

Hi,

A json string was sent from client side to asmx web service.

Here json string is as below

{"d":[
{"__type":"ProcedureAttributesService+AttributeObject","AttributeID":133,"DepartmentID":4,
"Name":"Ablation of Aflutter","BillingCode":"93651","ServiceCode":"1062","Value":1},
{"__type":"ProcedureAttributesService+AttributeObject","AttributeID":134,"DepartmentID":4,
"Name":"Ablation of Atrial tachy","BillingCode":"93651","ServiceCode":"1062","Value":1},
{"__type":"ProcedureAttributesService+AttributeObject","AttributeID":135,"DepartmentID":4,
"Name":"Ablation of AVN for CHB w/ or w/o temp pacer","BillingCode":"93650","ServiceCode":"1061","Value":1},
{"__type":"ProcedureAttributesService+AttributeObject","AttributeID":137,"DepartmentID":4,
"Name":"Ablation of VT","BillingCode":"93652","ServiceCode":"1063","Value&q

How to deserialize with XmlDocument and/or XmlDataProvider?

  

Hi. I have a set of classes set up that I have used in the past to deserialize with XmlSerializer:

	XmlSerializer serializer = new XmlSerializer(typeof(Foo));
	Foo foo = (Foo)serializer.Deserialize(stream);

What I would now like to do is embed that Xml in a Xaml file that is loaded at runtime using an XmlDataProvider:

	<XmlDataProvider x:Key="FooKey" >
		<x:XData>
		 ....
		</x:XData>
	</XmlDataProvider>

I'm loading the Xaml at runtime (it's a ResourceDictionary), extracting the XmlDataProvider and adding a callback for when the data has been loaded and is available:

	ResourceDictionary dictionary = (ResourceDictionary)XamlReader.Load(stream);
	XmlDataProvider provider = dictionary["FooKey"] as XmlDataProvider;
	provider.DataChanged += new EventHandler(provider_DataChanged);

My question is: in my provider_DataChanged handler, how do I deserialize that xml data given that XmlSerializer expects a str

Deserialize json into List

  

How can we Convert Json string into List<t> without using 3rd Party libraries. like json.net ..

Why cant we import the System.Runtime.Serialization.Json Library into codebehind.

I have a service wherei  am returning a json string of the List<t> to a wpf app..

There i need to convert back ...


Deserialize json into List

  

How can we Convert Json string into List<t> without using 3rd Party libraries. like json.net ..

Why cant we import the System.Runtime.Serialization.Json Library into codebehind.

I have a service wherei  am returning a json string of the List<t> to a wpf app..

There i need to convert back ...


how to serialize/deserialize image in vb.net

  

hi guys,

i need to serialize and deserialize an image for my project. i have been googling it for a few days but i cannot find any VB codes related to image serialization... can someone give me some hints on how i should start??

for my program, i need to save the image to sql database and then i need to retrieve all the image for my product catalog

thank you in advance for you help!

rgds,


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend