使用C#将数据集和关系序列化为XML

时间:2012-10-30 18:04:58

标签: c# xml dataset

我需要就以下问题提出一些意见/指示:

我需要一种方法将几个表中的行序列化为XML,其中值表示为属性,而不是标记。我已经开始深入研究数据集的WriteXML方法,但我不确定我是否可以按照我需要的方式自定义XML。它将采用以下格式:

<?xml version="1.0" encoding="UTF-8"?>
<Import operatorName="ABC123">
    <customers>
        <customer id="12345" firstName="Abraham" lastName="Lincoln" dob="02/12/1809">
            <addresses>
                <address city="the city" state="the state" zip="12345" street="the street">
                <address city="the city 2" state="the state 2" zip="54321" street="another street">
            </addresses>
            <customerEncounters>
                <customerEncounter id="797979" date="01/01/2013" location="somewhere"> 
                    <customerRepresentative name="The Dude">
                    <mechanic name="Mr. Mechanic"> 
                </customerEncounter>
            </customerEncounters>
            <customerEncounters>
                <customerEncounter id="888888" date="01/15/2013" location="somewhere else"> 
                    <customerRepresentative name="The Dude">
                    <mechanic name="Mr. Mechanic"> 
                </customerEncounter>
            </customerEncounters>
        </customer>
        <customer>
           ....
        </customer>
    </customers>
</Import>

简单地说,表格如下:

客户 ID FNAME L-NAME DOB

CustomerAddress ID 顾客ID 街 市 州 拉链

遭遇 ID 顾客ID 日期 地点 MechanicID CustRepID

力学 ID 名称

CustomerRepresentatives ID 名称

每个客户可以有很多地址和遭遇。

根据数据获取,我不会获得大量客户(50或更少)。这甚至可以用数据集吗?或者是否有更加资源友好的方式来做到这一点?

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,也许以下MSDN文章会有用:

Mapping Columns to XML Elements, Attributes, and Text

它解释了如何定义DataColumn中每个DataTables值的序列化方式。

相关问题