Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Serialize object to XML
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
XML
Title:
Serialize object to XML
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01611470
Message ID:
01611470
Views:
55
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
Next
Reply
Map
View

Click here to load this message in the networking platform