hi!
Can any plz guide us, how should we convert database table to .xml document.
Thanks in advance.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
naura paxRank #2,843 · 502 reputationPosted Oct 4, 2009, 9:54 PM EDT
You can use "XQuery/XPath" tools in your stored procedure to directly convert your table data to xml document.
Also you can retrieve data in your c# data and populate a dataset and use WriteXml method of database to create xml content and later save it as a file.
Please mark as answered if useful.
naura paxRank #2,843 · 502 reputationPosted Oct 4, 2009, 9:56 PM EDT
http://msdn.microsoft.com/en-us/library/ms345117(SQL.90).aspx
Roei BarRank #1,271 · 1.4K reputationPosted Oct 4, 2009, 10:12 PM EDT
private static XmlNode xmlBuilder(IDataReader reader) { XmlDocument xmlDoc = new XmlDocument(); XmlElement node = xmlDoc.CreateElement("Result"); xmlDoc.AppendChild(node); ArrayList arr = new ArrayList(); for (int i = 0; i < reader.FieldCount; ++i) { arr.Add(reader.GetName(i)); } while (reader.Read()) { XmlElement row = xmlDoc.CreateElement("Row"); for (int i = 0; i < arr.Count; ++i) { XmlAttribute att = xmlDoc.CreateAttribute((String)arr[i]); att.Value = reader.GetValue(i).ToString(); row.Attributes.Append(att); } node.AppendChild(row); } return xmlDoc; }