Dictionary à partir d'un dataset xml
Bonjour,
j'ai un dataset que j'écris dans un fichier xml
Code:
1 2
| DataSource.WriteXml("C:\test.xml", XmlWriteMode.WriteSchema)
XMLSource = New StreamReader("C:\test.xml").ReadToEnd() |
dans lequel on peut trouver par exemple ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
<xs:element name="PROPRIETAIRES">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" msdata:AutoIncrement="true"
type="xs:int" />
<xs:element name="Nom" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<PROPRIETAIRES>
<ID>1</ID>
<Nom>B</Nom>
<Prenom>A</Prenom>
<CP_ID>0</CP_ID>
<PAYS_ISOCode>BE</PAYS_ISOCode>
</PROPRIETAIRES>
<PROPRIETAIRES>
<ID>3</ID>
<Nom>B</Nom>
<Prenom>J</Prenom>
<Rue>Rue Clémenceau</Rue>
<Numero>2</Numero>
<CP_ID>0</CP_ID>
<PAYS_ISOCode>BE</PAYS_ISOCode>
</PROPRIETAIRES>
</xs:sequence>
</xs:complexType>
</xs:element> |
J'aimerais créer un Dictionary (key, value) mais je ne sais pas trop comment faire, j'ai fait ceci mais c'est incorrect :(
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Dim DocumentXML As New XmlDocument()
Dim params As IDictionary(Of String, String) = New Dictionary(Of String, String)
DocumentXML.Load("C:\test.xml")
Try
For Each DataRow As dsPrintParams.PRINT_PARAMSRow In Me.PrintParams.dsBD.PRINT_PARAMS.Select("TEMPLATEName = '" & TemplateName)
Dim Root As XmlElement = DocumentXML.SelectSingleNode("dsUrbanisme")
Dim Items As XmlNodeList(Items = Root.SelectNodes("xs:element"))
For Each Item As XmlElement In Items
Dim Key As String = Item.GetAttribute("name")
Dim Value As String = Item.GetAttribute(" ")
params.Add(Key, Value)
Next
Next
Catch e As NullReferenceException
MessageBox.Show(Err.Description)
End Try
Return params |