I have an xml document that I am creating using the loop below and the XML writer from C#. It currently works fine, but I wanted to implement a solution where every time the XML is written it automatically sorts it ascending using the driveStart field. I know people say you should do this in XSLT but I am having a hard time finding a good example to follow. Anyone have any experience in this that I can use? Any help is greatly appreciative.
XmlDocument doc = new XmlDocument();
XmlElement rn = doc.CreateElement("DriveLayout");
XmlElement dn = null;
XmlAttribute xa, xa1, xa2, xa3, xa4, xa5, xa6;
doc.AppendChild(rn);
foreach (GridItem item in this.fileSystemGrid.Items)
{
dn = doc.CreateElement("Drive");
xa = doc.CreateAttribute("driveTime");
xa.Value = item["DriveTime"].ToString();
xa1 = doc.CreateAttribute("driveStart");
xa1.Value = item["DriveStart"].ToString();
xa2 = doc.CreateAttribute("driveEnd");
xa2.Value = item["DriveEnd"].ToString();
}
dn.SetAttributeNode(xa);
dn.SetAttributeNode(xa1);
dn.SetAttributeNode(xa2);
rn.AppendChild(dn);
return doc.InnerXml;