wcf service returning data in xml

i have created the wcf service which is returning me XML.attached
is the format of table and presented data.

i want the data in xml as below.please let me know how can i approched this.
i have attached the wcf service files
i want this structure
 <provider_Name>Dr. Abc</provider_Name>

existing is giving like as below
    <Provider_Name>Dr. Abc</Provider_Name>
    <Provider_Name>Dr. Abc</Provider_Name>
    <Provider_Name>Dr. Abc</Provider_Name>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nicemanishAuthor Commented:
Hi Admin,

could i know why my question is neglected ...
at least provide some suggestion is this possible or not
Bob LearnedCommented:
Are you using DataSet.WriteXml?  If so, then I don't think that you can get the XML structure that you want.  I would suggest using LINQ-to-XML, and XDocument.
nicemanishAuthor Commented:

If you see below code which i write in svc file ,it is returning xml as string .so could you please provide whats the code i have to write to achieve that xml data.

            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select pt.PatientId,pr.Provider_Name,py.ProcedureName from Patient_Details pt,Provider_Details pr,Procedure_Details py where pt.Provider_Id=pr.ProviderId and pt.Procedure_Id=py.Procedure_Id and pt.PatientId= " + val1 + " Group By pt.PatientId,pr.Provider_Name,py.ProcedureName ", con);
            string s1;
            s1 = "";
            s1 = ds.GetXml();
            return s1;
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Bob LearnedCommented:
Something like this might work:

using System.Data;
using System.Linq;
using System.Xml.Linq;

namespace Demo
    public static class DataTableWriter

        /// <summary>
        /// Generate an XML document from a DataTable
        /// </summary>
        public static void WriteDataTable(DataTable dataTable, string fileName)
            var document = new XDocument();

            var rootElement = new XElement("Table");

            var rowList = dataTable.Rows.OfType<DataRow>();

            var row = rowList.FirstOrDefault();

            if (row == null)

            AddElementFromRowValue(rootElement, row, "PatientId");


        private static void AddElementFromRowValue(XElement parentElement, DataRow row, string name)
            var element = new XElement(name);

            var value = row[name].ToString();

            element.Value = value;


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Use an extension method like below

public static string ToXml(this DataTable table, int metaIndex = 0)
    XDocument xdoc = new XDocument(
        new XElement(table.TableName,
            from column in table.Columns.Cast<DataColumn>()
            where column != table.Columns[metaIndex]
            select new XElement(column.ColumnName,
                from row in table.AsEnumerable()
                select new XElement(row.Field<string>(metaIndex), row[column])

    return xdoc.ToString();
nicemanishAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.