mehmeto
mehmeto

Reputation: 1

I need to write a dataset as XML data

I need to generate the following xml output from the following dataset. I have attached the dataset and the xml output sample. I am going to put the C# code in a SSIS script task. Can you guys help me to write to code in C#. I am a database guy but i really don't know how this XML works with dataset. I'd really appricate if you can help. Thanks In advance.

AGENTID STARTDAY    STARTMONTH  STARTYEAR   STARTHOUR   STARTMINUTE ENDHOUR ENDMINUTE   EXCEPTION
910180  5   5   2011    10  30  11  0   OPEN
910180  5   5   2011    11  0   11  30  OPEN
910180  5   5   2011    11  30  12  0   OPEN
910180  6   5   2011    17  30  18  0   OPEN
910180  7   5   2011    18  0   18  30  OPEN
911568  6   5   2011    16  30  17  0   OPEN
911568  6   5   2011    19  0   19  30  OPEN
911568  6   5   2011    19  30  20  0   OPEN
911568  6   5   2011    20  0   20  30  OPEN
911568  6   5   2011    20  30  21  0   OPEN
911568  6   5   2011    21  0   21  30  OPEN
911568  6   5   2011    22  0   22  30  OPEN
911568  7   5   2011    10  30  11  0   OPEN
911568  7   5   2011    11  0   11  30  OPEN

 

<?xml version="1.0" encoding="ISO-8859-1" ?>
<agentScheduleList>
    <agent>
        <id>470185</id>
        <schedule>
            <day>12</day>
            <month>8</month>
            <year>2002</year>
            <exception>
                <startdate>
                    <day>12</day>
                    <month>8</month>
                    <year>2002</year>
                </startdate>
                <starttime>
                    <hour>22</hour>
                    <min>0</min>
                </starttime>
                <endtime>
                    <hour>2</hour>
                    <min>0</min>
                </endtime>
                <code>Open</code>
            </exception>
            <exception>
                <startdate>
                    <day>13</day>
                    <month>8</month>
                    <year>2002</year>
                </startdate>
                <starttime>
                    <hour>2</hour>
                    <min>0</min>
                </starttime>
                <endtime>
                    <hour>3</hour>
                    <min>0</min>
                </endtime>
                <code>Lunch</code>
            </exception>
            <exception>
                <startdate>
                    <day>13</day>
                    <month>8</month>
                    <year>2002</year>
                </startdate>
                <starttime>
                    <hour>3</hour>
                    <min>0</min>
                </starttime>
                <endtime>
                    <hour>7</hour>
                    <min>0</min>
                </endtime>
                <code>Open</code>
            </exception>
        </schedule>
    </agent>
    <agent>
        <id>470185</id>
        <schedule>
            <day>13</day>
            <month>8</month>
            <year>2002</year>
            <offexception/>
        </schedule>
    </agent>
</agentScheduleList>

Upvotes: 0

Views: 612

Answers (2)

Kelsey
Kelsey

Reputation: 47726

I think you can just use:

string xml = yourDataSet.GetXml();

You can read it back into a DataSet using the DataSet method ReadXml.

You can also use the following to get an XmlDataDocument:

System.Xml.XmlDataDocument xmlDoc = new System.Xml.XmlDataDocument(yourDataSet);

Upvotes: 1

Joel C
Joel C

Reputation: 5567

The DataSet class has a WriteXml function to write your data to a file, or GetXml to return it as a string. The documentation on MSDN has further explanation of customizing the output to get it to match exactly what you need, if your XML structure differs from your database structure.

Upvotes: 3

Related Questions