显示XML文档时排序数据

先看XML文档:

也可拷贝下面代码另存为XMl文档:

<stepList>
  <steps>
    <step>
      <order>1</order>
      <stepName>基丰盛的</stepName>
    </step>
    <step>
      <order>3</order>
      <stepName>个个个个</stepName>
    </step>
    <step>
      <order>2</order>
      <stepName>各个地方</stepName>
    </step>
  </steps>
</stepList>
View Code


想控order字段来排序,可以先存入一个集合中,如List<T>等 。面向对象,先创建一个对象吧:


下面是读xml文档,加载入List<T>集合中,然后使用OrderBy来进行排序。

有关读取xml文档,你还可以参考另外一篇:http://www.cnblogs.com/insus/p/4308740.html

显示结果:

原文地址:https://www.cnblogs.com/insus/p/4607166.html