Bonjour, je suis déjà tomber sur ce cas. car certains attribut ou elements étaient parfois facultatif. J'ai régler le problème ça en naviguant grâce à ca:
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
| 'INITIALISATION DU NAVIGATEUR
Dim xpathDoc As XPathDocument
xpathDoc = New XPathDocument(chemin)
Dim xmlNav As XPathNavigator
xmlNav = xpathDoc.CreateNavigator()
Dim xmlNI As XPathNodeIterator
Dim obj As Object
'INFORMATIONS
xmlNI = xmlNav.Select("/Noeud1t/@*")
Dim maClasse As New Classe
While (xmlNI.MoveNext())
Select Case xmlNI.Current.Name
Case "MonAttribut1"
obj = xmlNI.Current.Value
If IsNumeric(obj) Then
MaClasse.MonNumero = obj
End If
Case "MonAttribut2"
obj = xmlNI.Current.Value
If IsNumeric(obj) Then
MaClasse.MonNumero2 = obj
End If
End Select
End While |
le fait de mettre : @*, dans le navigateur, il va naviguer parmis tous les attribut. Si tu cherche des élément allant de 1 a n, ne rien mettre:
xmlNI = xmlNav.Select("/Noeud1t")
Partager