?
Solved

return SqlReader results as XML

Posted on 2013-11-20
2
Medium Priority
?
296 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 27

Accepted Solution

by:
Shaun Kline earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

719 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