我试图通过该元素中给出的属性来订购一些XML元素。这里是一个例子。
我希望它像这样..如下图所示(例子)
<root>
<firstTemplate name="someTestName" id="123123">
<element1>
<element2Name1 value="123" value2="324" value3="412" position="1"/>
<element2Name2 value="465" value2="552" value3="785" position="2"/>
<element2Name3 value="378" value2="857" value3="457" position="3"/>
</element1>
</firstTemplate>
</root>
但是当我用.net vb创建的程序完全解析Xml - visual basic时,使用XmlSerializer ..
<root>
<firstTemplate name="someTestName" id="123123">
<element1>
<element2Name2 value="123" value2="324" value3="412" position="2"/>
<element2Name1 value="772" value2="423" value3="331" position="1"/>
<element2Name3 value="432" value2="213" value3="775" position="3"/>
</element1>
</firstTemplate>
</root>
我希望按照该属性(位置)进行排序..从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
以下是课程
<XmlRoot("root")>
Public Class Templates
<XmlElement("firstTemplate")>
Public firstTemp as new List(Of Template)
End Class
Public Class Template
<XmlAttribute>
Public name as string
<XmlAttribute>
Public id as string
<XmlElement("element1")>
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..
<XmlElement> Public element2Name1 as New List(Of Type1)
<XmlElement> Public element2Name2 as New List(Of Type2)
<XmlElement> Public element2Name3 as New List(Of Type3)
<XmlElement> Public element2Name4 as New List(Of type4)
<XmlElement> Public element2Name5 as New List(Of type5)
End Class
PS:它是一个非常长的程序,所以我尽力缩小它,并显示代码的常见部分,我想这就是你要求的部分? ..
由于