<?xml version="1.0" standalone="yes"?> <qui xmlns="http://tempuri.org/qui.xsd"> 1 Toto 28 <sexe>m</sexe> 41 <taille>1.78</taille> 2 Tata 25 <sexe>f</sexe> 38 <taille>1.75</taille> 80 <tourTaille>60</tourTaille> <hanches>80</hanches> </qui>
MonDataSet.ReadXml("MonXml.xml")
MonDataSet.WriteXml("MonXml.xml")
For Each p As qui.personneRow In MonDataSet.personne Next
Imports System.Xml Public Class Infos Public id As Integer Public prenom As String Public age As Integer Public sexe As String Public Sub New(ByVal id, ByVal prenom, ByVal age, ByVal sexe) id = id prenom = prenom age = age sexe = sexe End Sub Public Sub New(ByVal noeud As XmlElement) For Each subNode As XmlElement In noeud.ChildNodes Select Case subNode.Name Case "id" id = XmlConvert.ToInt32(subNode.InnerText) Case "prenom" prenom = subNode.InnerText Case "age" age = XmlConvert.ToInt32(subNode.InnerText) Case "sexe" sexe = subNode.InnerText End Select Next End Sub End Class Public Class Taille Public pointure As Integer Public hauteur As Single Public Sub New(ByVal pointure As Integer, ByVal hauteur As Single) pointure = pointure hauteur = hauteur End Sub Public Sub New(ByVal noeud As XmlElement) For Each subNode As XmlElement In noeud.ChildNodes Select Case subNode.Name Case "pointure" pointure = XmlConvert.ToInt32(subNode.InnerText) Case "hauteur" hauteur = XmlConvert.ToSingle(subNode.InnerText) End Select Next End Sub End Class Public Class Mensurations Public poitrine As Integer Public taille As Integer Public hanches As Integer Public Sub New(ByVal poitrine As Integer, ByVal taille As Integer, ByVal hanches As Integer) poitrine = poitrine taille = taille hanches = hanches End Sub Public Sub New(ByVal noeud As XmlElement) For Each subNode As XmlElement In noeud.ChildNodes Select Case subNode.Name Case "poitrine" poitrine = XmlConvert.ToInt32(subNode.InnerText) Case "taille" taille = XmlConvert.ToInt32(subNode.InnerText) Case "hanches" hanches = XmlConvert.ToInt32(subNode.InnerText) End Select Next End Sub End Class Public Class Personne Private _infos As Infos Private _taille As Taille Private _mensurations As Mensurations Public Property Infos() As Infos Get Return _infos End Get Set(ByVal value As Infos) _infos = value End Set End Property Public Property Taille() As Taille Get Return _taille End Get Set(ByVal value As Taille) _taille = value End Set End Property Public Property Mensurations() As Mensurations Get Return _mensurations End Get Set(ByVal value As Mensurations) _mensurations = value End Set End Property Public Sub New(ByVal infos As Infos, ByVal taille As Taille, ByVal mensurations As Mensurations) _infos = infos _taille = taille _mensurations = mensurations End Sub Public Sub New(ByVal noeud As XmlElement) _infos = Nothing _taille = Nothing _mensurations = Nothing For Each subNode As XmlElement In noeud.ChildNodes Select Case subNode.Name Case "infos" _infos = New Infos(subNode) Case "taille" _taille = New Taille(subNode) Case "mensurations" _mensurations = New Mensurations(subNode) End Select Next End Sub End Class
Private Function LoadXML() As List(Of Personne) Dim doc As New XmlDocument() doc.Load("C:\tmp.xml") Dim lst As New List(Of Personne) For Each elm As XmlElement In doc.DocumentElement.ChildNodes lst.Add(New Personne(elm)) Next Return lst End Function
Dim lst As List(Of Personne) = LoadXML() Dim res As String For Each p As Personne In lst res = "" If p.Infos IsNot Nothing Then res String.Format("Infos : id {0} ; prenom = {1} ; age = {2} ; sexe = {3}", p.Infos.id, p.Infos.prenom, p.Infos.age, p.Infos.sexe) res = res & vbNewLine End If If p.Taille IsNot Nothing Then res &String.Format("Taille : pointure {0} ; hauteur = {1}", p.Taille.pointure, p.Taille.hauteur) res &= vbNewLine End If If p.Mensurations IsNot Nothing Then res &String.Format("Mensurations : poitrine {0} ; taille = {1} ; hanches = {2}", p.Mensurations.poitrine, p.Mensurations.taille, p.Mensurations.hanches) res &= vbNewLine End If MsgBox(res) Next
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question