<Dictrionary>
  <A>
    <Dic name="Awa" />
    <Dic name="Ac" />
    <Dic name="Aa" />
  </A>
  <B>
    <Dic name="Bz" />
    <Dic name="Bc"  />
    <Dic name="Ba"  />
  </B>
....
</Dictrionary>使它们按照,name属性按字母排序。

解决方案 »

  1.   

    XPathExpression
    http://dotnet.aspx.cc/article/8C7170E2-DB55-41F1-8C40-FB7F0F9ADAA5/read.aspx
      

  2.   

    将XML转入dataset..用datatable.select()排序一下。再转换成XML。。你试试吧。
      

  3.   

    你查查xslt语法,里面有的!!
    帮你顶!!
      

  4.   

      DataSet ds = new DataSet();
                ds.ReadXml((Stream)new FileStream(Path.Combine(Application.StartupPath, "XMLFile1.xml"), FileMode.Open));
                DataRow[] dr_Array =  ds.Tables[1].Select("  ", "  name DESC");//这里有多个表,还不清楚XML转到DATATABLE是怎样的过程。
                DataTable dtt = ds.Tables[1].Clone();
                foreach (DataRow dr in dr_Array)
                {
                    dtt.Rows.Add(dr.ItemArray);
                }
                this.dataGridView1.DataSource = dtt;
                dtt.WriteXml("c:\\aa.xml");这段代码可以实现功能。
    但还是有点问题,,你自己研究一下吧。
      

  5.   

    楼上的,不行呀!转完变成:
    <?xml version="1.0" standalone="yes"?>
    <DocumentElement>
      <Dic name="Aa" />
      <Dic name="Ac" />
      <Dic name="Awa" />
      <Dic name="Ba" />
      <Dic name="Bc" />
      <Dic name="Bz" />
    </DocumentElement>
      

  6.   

                XmlDocument doc = new XmlDocument();
                doc.Load(@"D:\Project\C#Test\WindowsApplication1\WindowsApplication3\Config.xml");
                XmlNodeList nodeList = doc.SelectNodes("/Dictrionary/*/*");            List<XmlElement> list = new List<XmlElement>();
                foreach (XmlElement el in nodeList)
                {
                    list.Add(el);
                }            list.Sort(new sort());            XmlNode node = doc.SelectSingleNode("/Dictrionary");
                int index = 0;
                foreach (XmlNode n in node.ChildNodes)
                {                int count = n.ChildNodes.Count;
                    n.RemoveAll();                for (int j = index; j < list.Count; j++)
                    {
                        n.AppendChild(list[j]);
                        index++;
                        if (index == count)
                            break;
                    }
                }
                doc.Save(@"D:\Project\C#Test\WindowsApplication1\WindowsApplication3\Config.xml");
          public class sort : IComparer<XmlElement>
            {
                #region IComparer<XmlNode> Members            public int Compare(XmlElement x, XmlElement y)
                {
                    return string.Compare(x.Attributes[0].Value, y.Attributes[0].Value);
                }            #endregion
            }
    帮你顶下。
      

  7.   

    string xmlPath = "e:\\2.xml";
    XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load(xmlPath);
    XPathDocument pathdoc = new XPathDocument(xmlPath);
    XmlNodeList ndoes = xmldoc.DocumentElement.ChildNodes;
    foreach (XmlNode node in ndoes)
    {
        XPathNavigator nav = pathdoc.CreateNavigator();
        string xpath = String.Format("/Dictrionary/{0}/Dic", node.Name);
        XPathExpression exp = nav.Compile(xpath);
        exp.AddSort("@name", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text);
        XPathNodeIterator nodeIter = nav.Select(exp);
        node.RemoveAll();
        while (nodeIter.MoveNext())
        {
            XmlElement xe = xmldoc.CreateElement("Dic");    
            xe.SetAttribute("name", nodeIter.Current.GetAttribute("name", ""));
            node.AppendChild(xe);
        }
    }
    xmldoc.Save(xmlPath);