日期:2014-05-18  浏览次数:21164 次

又有新问题了,DataTable写入Xml问题,急急急!!!
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));
急啊,大家快帮帮忙吧!

------解决方案--------------------
尝试着弄个DataSet tablename设为VoucherSet 在WriteXml试试
------解决方案--------------------
VoucherSet不就是DataSet的名字吗?而Voucher则是DataTable的名字,你是从DataTable输出的,缺少DataSet的命名设置。