我想要做的是将数据集转换为xml字符串。其中t返回包含带有数据表名称的datasetname的输出。只是我想删除数据表名称,并希望仅与数据集节点标记名称绑定。我该怎么办。这是我的代码。
if (sID > 0)
{
String retXml = String.Empty;
DataSet ds = new DataSet();
DataTable dtpdfAndEmailInfo = new DataTable("pdfandemailinfo");
DataRow dr = dtpdfAndEmailInfo.NewRow();
dtpdfAndEmailInfo.Clear();
dtpdfAndEmailInfo.Columns.Add("mailFrom", typeof(string));
dtpdfAndEmailInfo.Columns.Add("mailTo", typeof(string));
dtpdfAndEmailInfo.Columns.Add("mailCC", typeof(string));
dtpdfAndEmailInfo.Columns.Add("mailBCC", typeof(string));
dtpdfAndEmailInfo.Columns.Add("mailSubject", typeof(string));
dtpdfAndEmailInfo.Columns.Add("salesorderpdfurl", typeof(string));
ds.Tables.Add(dtpdfAndEmailInfo);
dtpdfAndEmailInfo.Rows.Add(dr);
String fileDirectory="D:\\po\\Sandbox\\po\\BOID_858_ORGID_571\\SalesOrderPdf\\" ;
String FileName ="BOID_858_SOID_151382.pdf";
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
ds.Tables[0].Rows[i]["mailFrom"] = "someemailid@yopmail.com";
ds.Tables[0].Rows[i]["mailTo"] = "someemailid1@yopmail.com";
ds.Tables[0].Rows[i]["mailCC"] = "someemailid2@yopmail.com";
ds.Tables[0].Rows[i]["mailSubject"] = "Test";
if (System.IO.File.Exists(Path.Combine(fileDirectory, FileName)))
{
ds.Tables[0].Rows[i]["SalesOrderPdfURL"] = Path.Combine(fileDirectory, FileName);
}
else
{
ds.Tables[0].Rows[i]["SalesOrderPdfURL"] = "";
}
}
Cmd.ResponseStatus.RowCount = ds.Tables[0].Rows.Count;
retXml = Util.GetXmlList(ds, "salesorderPdfAndEmailInfo", "pdfandemailinfos");
}
public static string GetXmlList(DataSet ds, String rootNode, String itemNode)
{
return GetXmlList(ds, rootNode, @"cls=""dataArray""", itemNode, @"cls=""dataItem""");
}
public static string GetXmlList(DataSet ds, String rootNode, String rootAttribute, String itemNode, String itemAttribute)
{
String rootNodeStartTag = String.Format("<{0} {1}>", rootNode, rootAttribute);
String rootNodeEndTag = String.Format("</{0}>", rootNode);
String nodeStartTag = String.Format("<{0} {1}>", itemNode, itemAttribute);
String nodeEndTag = String.Format("</{0}>", itemNode);
string retXML = ds.GetXml().Replace("<NewDataSet>", rootNodeStartTag).Replace("<Table>", nodeStartTag).Replace("</NewDataSet>", rootNodeEndTag).Replace("</Table>", nodeEndTag);
return HttpUtility.HtmlDecode(retXML);
}
这是我的回复
"salesorderPdfAndEmailInfo": {
"pdfandemailinfo": {
"mailFrom": "someemailid@yopmail.com",
"mailTo": "someemailid1@yopmail.com",
"mailCC": "someemailid2@yopmail.com",
"mailSubject": "Test",
"salesorderpdfurl": "http://localhost/por/D:\\po\\Sandbox\\po\\BOID_858_ORGID_571\\SalesOrderPdf\\BOID_858_SOID_151382.pdf"
}
}
我想要的响应应该是删除数据表节点标记名称。任何帮助都将被欣赏。 回应应该是这样的..
"salesorderPdfAndEmailInfo": {
"mailFrom": "someemailid@yopmail.com",
"mailTo": "someemailid1@yopmail.com",
"mailCC": "someemailid2@yopmail.com",
"mailSubject": "Test",
"salesorderpdfurl": "http://localhost/por/D:\\po\\Sandbox\\po\\BOID_858_ORGID_571\\SalesOrderPdf\\BOID_858_SOID_151382.pdf"
}