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 ds = new DataSet("VoucherSet"); ds.Tables.Add(table); ds.WriteXml(GetXmlFullPath(xmlName));
谢谢!
用Linq TO XML吧朋友,你自己能搞定的
table.DataSet.Name="VoucherSet"?