Solved

return SqlReader results as XML

Posted on 2013-11-20
2
293 Views
Last Modified: 2013-11-20
Hi,

I have an interface in a Web service that returns XML output. The output is queried from a MS SQL database by caling stored procedure. While the stored proc itself is not returning XML, and I don't have any control over it, I need to return the result set as XML.

Right now, I'm using  XmlWriter.

            
            StringBuilder sbLog = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sbLog);
            writer.WriteStartDocument();
            writer.WriteStartElement("LogSet");

            while (sqlRdr.Read())
            {
                writer.WriteStartElement("Log");

                writer.WriteStartElement("EntryID");
                writer.WriteValue(sqlRdr["EntryID"].ToString());
                writer.WriteEndElement();

               //and so on

Open in new window


Is there an easier, elegant way  to do this?

thanks!
0
Comment
Question by:Mydeen Yussouf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39662382
A similar question was asked on StackOverflow: (stackoverflow.com/questions/16768263/generate-xml-using-c-sharp-from-sql-server-data).

In this example, the data was returned into a DataTable using a SQLDataAdapter. From there, the methods WriteXml and WriteXmlSchema were used.
0
 
LVL 1

Author Closing Comment

by:Mydeen Yussouf
ID: 39662660
yeah I posted that question too :-)
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question