<newDataSet>
<people id="1">
<name>1111</name>
<sex>1</sex>
</people>
</newDataSet>
就是相应的结点要有一个属性。这个直接用Dataset输出就不行。只能进行XML重构来处理。
XmlTextWriter writer
=
new
XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4 ;
writer.IndentChar = ' ' ;
writer.WriteRaw( " <?xml version=\ " 1.0 \ " ?> " );
writer.WriteStartElement( " Yuanlin " );
// writer.e
for ( int i = 0 ;i < dt.Rows.Count;i ++ )
{
writer.WriteStartElement("Corp");
writer.WriteAttributeString("id",dt.Rows.Count.ToString());
writer.WriteStartElement("CorpInfo");
writer.WriteElementString("Name",dt.Rows[i]["Name"].ToString());
writer.WriteElementString("AptLevel",dt.Rows[i]["AptLevel"].ToString());
writer.WriteElementString("CropBirthDate",dt.Rows[i]["CropBirthDate"].ToString());
writer.WriteElementString("ManageDept",dt.Rows[i]["ManageDept"].ToString());
writer.WriteElementString("Province",dt.Rows[i]["Province"].ToString());
writer.WriteElementString("City",dt.Rows[i]["City"].ToString());
writer.WriteElementString("Region",dt.Rows[i]["Region"].ToString());
writer.WriteElementString("Address",dt.Rows[i]["Address"].ToString());
writer.WriteEndElement();
//获取人员信息
DataView dv = DtEmployee.DefaultView;
dv.RowFilter = String.Format("FBaseInfoID='{0}'",dt.Rows[i]["FID"].ToString());
for(int j=0;j<dv.Count;j++)
{
writer.WriteStartElement("USerInfo");
writer.WriteElementString("Name",dv[j].Row["Name"].ToString());
writer.WriteElementString("Sex",dv[j].Row["Sex"].ToString());
writer.WriteElementString("CardCode",dv[j].Row["CardCode"].ToString());
writer.WriteElementString("Specialty",dv[j].Row["Specialty"].ToString());
writer.WriteElementString("Duty",dv[j].Row["Duty"].ToString());
writer.WriteEndElement();
}
dv = DtProject.DefaultView;
dv.RowFilter = String.Format("FBaseInfoID='{0}'",dt.Rows[i]["FID"].ToString());
for(int j=0;j<dv.Count;j++)
{
writer.WriteStartElement("ProjectInfo");
writer.WriteElementString("FProjectName",dv[j].Row["FProjectName"].ToString());
writer.WriteElementString("FProvince",dv[j].Row["FProvince"].ToString());
writer.WriteElementString("FCity",dv[j].Row["FCity"].ToString());
writer.WriteElementString("FRegion",dv[j].Row["FRegion"].ToString());
writer.WriteElementString("FProjectType",dv[j].Row["FProjectType"].ToString());
writer.WriteElementString("FArea",dv[j].Row["FArea"].ToString());
writer.WriteElementString("FPrice",dv[j].Row["FPrice"].ToString());
writer.WriteElementString("FCompleteArea",dv[j].Row["FCompleteArea"].ToString());
writer.WriteElementString("FCompleteCost",dv[j].Row["FCompleteCost"].ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
Response.AddHeader( " Content-Disposition " , " attachment; filename=Acounts.xml " );
this .Response.ContentType = " text/xml " ;
Response.ContentType = " application/octet-stream " ;
writer.Flush();
Response.End();
writer.Close();
writer.Formatting = Formatting.Indented;
writer.Indentation = 4 ;
writer.IndentChar = ' ' ;
writer.WriteRaw( " <?xml version=\ " 1.0 \ " ?> " );
writer.WriteStartElement( " Yuanlin " );
// writer.e
for ( int i = 0 ;i < dt.Rows.Count;i ++ )
{
writer.WriteStartElement("Corp");
writer.WriteAttributeString("id",dt.Rows.Count.ToString());
writer.WriteStartElement("CorpInfo");
writer.WriteElementString("Name",dt.Rows[i]["Name"].ToString());
writer.WriteElementString("AptLevel",dt.Rows[i]["AptLevel"].ToString());
writer.WriteElementString("CropBirthDate",dt.Rows[i]["CropBirthDate"].ToString());
writer.WriteElementString("ManageDept",dt.Rows[i]["ManageDept"].ToString());
writer.WriteElementString("Province",dt.Rows[i]["Province"].ToString());
writer.WriteElementString("City",dt.Rows[i]["City"].ToString());
writer.WriteElementString("Region",dt.Rows[i]["Region"].ToString());
writer.WriteElementString("Address",dt.Rows[i]["Address"].ToString());
writer.WriteEndElement();
//获取人员信息
DataView dv = DtEmployee.DefaultView;
dv.RowFilter = String.Format("FBaseInfoID='{0}'",dt.Rows[i]["FID"].ToString());
for(int j=0;j<dv.Count;j++)
{
writer.WriteStartElement("USerInfo");
writer.WriteElementString("Name",dv[j].Row["Name"].ToString());
writer.WriteElementString("Sex",dv[j].Row["Sex"].ToString());
writer.WriteElementString("CardCode",dv[j].Row["CardCode"].ToString());
writer.WriteElementString("Specialty",dv[j].Row["Specialty"].ToString());
writer.WriteElementString("Duty",dv[j].Row["Duty"].ToString());
writer.WriteEndElement();
}
dv = DtProject.DefaultView;
dv.RowFilter = String.Format("FBaseInfoID='{0}'",dt.Rows[i]["FID"].ToString());
for(int j=0;j<dv.Count;j++)
{
writer.WriteStartElement("ProjectInfo");
writer.WriteElementString("FProjectName",dv[j].Row["FProjectName"].ToString());
writer.WriteElementString("FProvince",dv[j].Row["FProvince"].ToString());
writer.WriteElementString("FCity",dv[j].Row["FCity"].ToString());
writer.WriteElementString("FRegion",dv[j].Row["FRegion"].ToString());
writer.WriteElementString("FProjectType",dv[j].Row["FProjectType"].ToString());
writer.WriteElementString("FArea",dv[j].Row["FArea"].ToString());
writer.WriteElementString("FPrice",dv[j].Row["FPrice"].ToString());
writer.WriteElementString("FCompleteArea",dv[j].Row["FCompleteArea"].ToString());
writer.WriteElementString("FCompleteCost",dv[j].Row["FCompleteCost"].ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
Response.AddHeader( " Content-Disposition " , " attachment; filename=Acounts.xml " );
this .Response.ContentType = " text/xml " ;
Response.ContentType = " application/octet-stream " ;
writer.Flush();
Response.End();
writer.Close();