Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there

I want to save data in Xml to a database as a string but am not familiar with Xml.

Basically, would like a simple C# example where an Xml document is created (the data doesn't matter), and the characters are saved in a string to be saved in a database.

Any ideas?
Posted
Comments
AspDotNetDev 28-Jul-10 18:42pm    
I deleted your answer as it was not really an answer. Rather than post an answer, you can also post a comment on an existing answer (kind of like how I'm posting a comment to your question) or update your original question. However, for what you posted, I would say the more appropriate thing to do would be to Google for an answer and, if that failed, ask another question (as an entirely different question rather than adding to this one). Also, the best way to thank somebody for an answer is to rate it and mark it as an accepted solution (wink wink, nudge nudge).

1 solution

Here is a very simple example.
C#
/* Create XML document. */
System.Xml.XmlDocument d = new System.Xml.XmlDocument();
d.LoadXml(@"<animals><dog name=""Ruff"" /><cat name=""Nip"" /></animals>");

/* Get XML as string. */
string str = d.OuterXml;

Save that string to the database as you would any other string. Make sure to use a data type that can hold a long string (if your XML has the potential to be large).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900