Ich schreibe erfolgreich eine XML Datei mit diesem Code weg:
und möchte die XML nun wieder in ein dictionary im dictionary einlesen:
In der Loop, zwischen Zeile 18 und 34 bekommen ich die Zuweisung zum dictionary im dictionary nicht hin. Die hier aufgeführte Loop funktioniert einwandfrei für ein "einfaches" dictionary. Kann mir jemand auf die Sprünge helfen?
VB.NET-Quellcode
- Public Sub SaveNestedXmlFile(ByVal file As String, ByVal key1Name As String, ByVal key2Name As String, ByVal attributeName As String, ByVal dictionaryName As Dictionary(Of String, Dictionary(Of String, String)))
- Dim xw As XmlTextWriter = New XmlTextWriter(file, New UnicodeEncoding)
- xw.WriteStartDocument()
- xw.WriteStartElement(key1Name)
- Dim x As Integer = 0
- For Each pair In dictionaryName
- xw.WriteStartElement("id" & pair.Key)
- For Each subpair In pair.Value
- Dim k2 As String = subpair.Key
- Dim v2 As String = subpair.Value
- xw.WriteStartElement(attributeName)
- xw.WriteAttributeString(k2, v2)
- xw.WriteEndElement()
- Next
- xw.WriteEndElement()
- x = x + 1
- Next
- xw.WriteEndElement()
- xw.Close()
- LogInfo("saved nested XML file: " & file)
- End Sub
und möchte die XML nun wieder in ein dictionary im dictionary einlesen:
VB.NET-Quellcode
- Public Sub ReadNestedXmlFile(ByVal file As String, ByVal dictionaryName As Dictionary(Of String, Dictionary(Of String, String)))
- ' Lesen einer "verschachtelten" XML Datei
- If Not My.Computer.FileSystem.FileExists(file) Then
- MsgBox("Die angebenen Datei '" & file & "' konnte nicht gefunden werden")
- Exit Sub
- End If
- Dim xr As XmlReader = New XmlTextReader(file)
- Do While xr.Read()
- If xr.NodeType = XmlNodeType.Element Then
- If xr.AttributeCount > 0 Then
- Do While xr.MoveToNextAttribute()
- dictionaryName(xr.Name) = xr.Value
- Loop
- End If
- End If
- Loop
- xr.Close()
- LogInfo("imported XML file: " & ExtractFilename(file))
- End Sub
In der Loop, zwischen Zeile 18 und 34 bekommen ich die Zuweisung zum dictionary im dictionary nicht hin. Die hier aufgeführte Loop funktioniert einwandfrei für ein "einfaches" dictionary. Kann mir jemand auf die Sprünge helfen?