Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serialize object to XML
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
XML
Titre:
Serialize object to 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:
01611470
Vues:
54
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.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform