I have to read data from an XML file and the order is important
I have the following (simplified) XML data which I need to read:
<xmltest>
<type1>
<tekst>ABC</tekst>
</type1>
<type2>
<tekst>DEF</tekst>
</type2>
<type1>
<tekst>GHI</tekst>
</type1>
<type2>
<tekst>JKL</tekst>
</type2>
<type3>
<tekst>MNO</tekst>
</type3>
</xmltest>
The following classes are made:
public class xmltest
public property type1 as list(of type1)
public property type2 as list(of type2)
public property type3 as list(of type3)
end class
public class type1
public property tekst as string
end class
public class type2
public property tekst as string
end class
public class type3
public property tekst as string
end class
I use the following code to read the XML:
Public Sub Indlaes
Dim reader As New System.Xml.XmlTextReader("filename.txt")
Dim subreader As System.Xml.XmlReader
Dim xmlSer As System.Xml.Serialization.XmlSerializer
Dim result = New cmltest
Do While (reader.Read())
Select Case reader.NodeType
Case System.Xml.XmlNodeType.Element
subreader = reader.ReadSubtree()
xmlSer = New System.Xml.Serialization.XmlSerializer(result.GetType)
result = xmlSer.Deserialize(subreader)
subreader.Close()
End Select
Loop
reader.Close()
End Sub
In the above example I end up with 3 lists inside the xmltest but can't recreate the order
I'm thinking about using a dictionary with an ID used across the 3 lists/dictionaries, but how do I get the ID's set? Or is there any other solution?
I would really want to keep using the Deserialize function as it is used for the rest of the xml data also