可以在xml中靠增加属性来实现分组
可以在一篇xml文档中,靠增加一个行的属性,来进行排序。
有这方面需求的folks,请参考如下代码:
private void UniteHtmlCell(ref XmlDocument xDocument)
{
int rowsCount = xDocument.DocumentElement.ChildNodes.Count;//xml文档的行数
for (int i = 0; i < rowsCount; i++)
{
string rowgroup = i.ToString();
XmlNode rowi = xDocument.DocumentElement.ChildNodes[i];//i行的TestCategory级别
XmlNode sub_rowi = rowi.FirstChild;//Test级别
XmlNode ssub_rowi = sub_rowi.FirstChild;//result级别
XmlElement xe1 = (XmlElement)ssub_rowi;
//label1.Text = xe1.GetAttribute("buginfo");
if (xe1.GetAttribute("buginfo") != "" && xe1.GetAttribute("buginfo") != "-")
{
int groupRowsCount = 1;
xe1.SetAttribute("rowgroup", rowgroup);
for (int j = i + 1; j < rowsCount; j++)
{
XmlNode rowj = xDocument.DocumentElement.ChildNodes[j];//j行的TestCategory级别
XmlNode sub_rowj = rowj.FirstChild;//Test级别
XmlNode ssub_rowj = sub_rowj.FirstChild;//result级别
XmlElement xe2 = (XmlElement)ssub_rowj;
if (xe1.GetAttribute("buginfo") == xe2.GetAttribute("buginfo").ToString())
{
groupRowsCount++;
XmlElement xe = (XmlElement)ssub_rowj;
xe.SetAttribute("buginfo", "");//靠这个属性来
xe.SetAttribute("rowgroup", rowgroup);
}
}
//在具有相同buginfo的result级别添加属性groupRowsCount,这样就可以在xslt(已经按照buginfo排序)文件中实现单元格的合并
string grCount = groupRowsCount.ToString();
XmlElement xe3 = (XmlElement)ssub_rowi;
xe3.SetAttribute("groupRowsCount", grCount);
}
}
}