一千萬個為什麽

搜索

如何根據屬性對元素進行排序/排序?

我試圖通過在該元素中給出的屬性來排列一些XML元素..這裏是一個例子。

我希望它是這樣的..如下所示(示例)


  
   
       
       
       
   
  

但是當我完全分析Xml與我的程序創建.net vb - visual basic,使用XmlSerializer ..


  
   
       
       
       
   
  

我希望它根據該屬性(位置)排序..從1到3或更多....我嘗試過尋找無處不在和很多問題。所以我決定在這裏提出我的第一個問題.. :)。

編輯:

Public Sub Start()

     Dim clientInfoSerializer As New XmlSerializer(GetType(client_infos))

     Dim TemplateWriter As New XmlSerializer(GetType(Templates))

     Dim Writer As New StreamWriter(My.Application.Info.DirectoryPath + "\Parsed\templates.xml")

     ''File Reader
     Dim fileReader As New StreamReader(My.Application.Info.DirectoryPath + "\client_infos.xml")

     ''Loading files
     Dim Out As client_infos = CType(clientInfoSerializer.Deserialize(fileReader), client_infos)


     Dim temp as new Templates

     For Each template in Out.temps

         ''Here adds the required elements and attributes to temp varaible..


     Next



     TemplateWriter.Serialize(Writer, temp)

     Writer.close()
     fileReader.close()


EndSub

這裏是類


Public Class Templates

    
    Public firstTemp as new List(Of Template)

End Class

Public Class Template

    
    Public name as string

    
    Public id as string

    
    Public element1 as new List(Of elementTypes)

End Class


Public Class elementTypes

    ''inside these Type1,Type2, there are just some attributes and elements, Including position attribute (as a seperate abstract class, that inherits all)
    ''Possible that element2Name3 also might get position="1".. in that case element2Name3 must be at top (order first..) , so it depends on the position attribute..
     Public element2Name1 as New List(Of Type1)
     Public element2Name2 as New List(Of Type2)
     Public element2Name3 as New List(Of Type3)
     Public element2Name4 as New List(Of type4)
     Public element2Name5 as New List(Of type5)

End Class

PS:它是一個非常長的程序,所以我盡我所能縮小它,並顯示代碼的公共部分,我想這就是你要求的部分? ..

謝謝

最佳答案

暫時沒有最佳答案

轉載註明原文: 如何根據屬性對元素進行排序/排序?