Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serialize object to XML
Message
Information générale
Forum:
ASP.NET
Catégorie:
XML
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01611470
Message ID:
01611477
Vues:
58
This message has been marked as a message which has helped to the initial question of the thread.
I would probably use JSON instead of XML. Reason: it's easier to do the serialization and JSON serialization can handle a lot more types than
XmlSerialization can and the data produced is actually smaller as well.

* JsonConvert.Serialize()
* JsonConvertDeserialize< t >()

using Json.NET (which is default requirement on all web projects anyway).

+++ Rick ---


>Hi everybody,
>
>I found this code on stackoverflow
>
>
> public static string SerializeObject(this object obj)
>        {
>            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
>            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
>            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
>            {
>                serializer.Serialize(ms, obj);
>                ms.Position = 0;
>                xmlDoc.Load(ms);
>                return xmlDoc.InnerXml;
>            }
>        }
>
>and I am wondering what do you use normally? I am passing the XML to SQL Server and I need to parse it into the table and I am having troubles.
>
>My class is very simple
>
>InvoiceNo decimal
>Payment decimal
>
>and the object contains list of such objects.
>
>Thanks a lot in advance.
>
>UPDATE. The code seemed to work OK in my tests, although so far I tested the SP only. I haven't yet tested it from the application.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform