首页 新闻 搜索 专区 学院

DataTable写入Xml问题,急急急!!!

0
悬赏园豆:100 [已解决问题] 解决于 2012-08-06 10:43

xml标准格式是这样的:

<?xml version="1.0" standalone="yes"?>
<VoucherSet>
  <Voucher>
    <segment>会员卡</segment>
    <payment>现金</payment>
    <summary>1</summary>
    <subjectType>现金</subjectType>
    <subject>1</subject>
    <memo>1</memo>
  </Voucher>
</VoucherSet>

代码生成后:

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <Voucher>
    <segment>会员卡</segment>
    <payment>现金</payment>
    <summary>1</summary>
    <subjectType>现金</subjectType>
    <subject>1</subject>
    <memo>1</memo>
  </Voucher>
</DocumentElement>

对于这个<DocumentElement>我应该如何设置???

C#代码如下:

            DataTable dt = new DataTable("Voucher");
            dt.Columns.Add(new DataColumn("segment"));
            dt.Columns.Add(new DataColumn("payment"));
            dt.Columns.Add(new DataColumn("summary"));
            dt.Columns.Add(new DataColumn("subjectType"));
            dt.Columns.Add(new DataColumn("subject"));
            dt.Columns.Add(new DataColumn("memo"));
            int count = this.dgvVoucherSet.Rows.Count -1;  //取到 凭证设置 行数(-1:去掉空行)
            for (int i = 0; i < count; i++)  
            {
                string segment = dgvVoucherSet.Rows[i].Cells["segment"].Value.ToString();  //业务分类 
                string payment = dgvVoucherSet.Rows[i].Cells["payment"].Value.ToString();  //支付方式
                string summary = dgvVoucherSet.Rows[i].Cells["summary"].Value.ToString();  //摘要
                string subjectType = dgvVoucherSet.Rows[i].Cells["subjectType"].Value.ToString();   //科目类型
                string subject = dgvVoucherSet.Rows[i].Cells["subject"].Value.ToString();  //会计科目
                string memo = dgvVoucherSet.Rows[i].Cells["memo"].Value.ToString();  //备注

                DataRow dr = dt.NewRow();
                dr["segment"] = segment;
                dr["payment"] = payment;
                dr["summary"] = summary;
                dr["subjectType"] = subjectType;
                dr["subject"] = subject;
                dr["memo"] = memo;
                dt.Rows.Add(dr);
            }
            dt.WriteXml(GetXmlFullPath(xmlName));

急啊,大家快帮帮忙吧!

hunaifei的主页 hunaifei | 初学一级 | 园豆:87
提问于:2012-08-02 15:52
< >
分享
最佳答案
0
DataSet ds = new DataSet("VoucherSet");
ds.Tables.Add(table);
ds.WriteXml(GetXmlFullPath(xmlName));
收获园豆:70
gunsmoke | 老鸟四级 |园豆:3592 | 2012-08-03 06:53

谢谢!

hunaifei | 园豆:87 (初学一级) | 2012-08-06 10:43
其他回答(2)
0

用Linq TO XML吧朋友,你自己能搞定的

收获园豆:10
leeoleVis | 园豆:43 (初学一级) | 2012-08-02 16:10
0

table.DataSet.Name="VoucherSet"?

收获园豆:20
mr.cui | 园豆:171 (初学一级) | 2012-08-02 21:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册