Bonjour,
tout bêtement, j'essaie de lire un fichier XML dont je connais la structure mais n'étant pas une pro du dév en VB, je galère!
Fichier xml :
<commande>
<idcommande>10999</idcommande>
<datecommande>2015-07-19</datecommande>
<lignes>
<article0>
<ref0>test 0</ref0>
<designation0>article de test 0</designation0>
<prixunitht0>25</prixunitht0>
<quantite0>1</quantite0>
</article0>
<article1>
<ref1>test 1</ref1>
<designation1>article de test 1</designation1>
<prixunitht1>10</prixunitht1>
<quantite1>2</quantite1>
</article1>
</lignes>
</commande>
J'ai créé une petite fonction qui renvoie (est censée renvoyer...) la valeur du noeud passé en paramètre :
et ma procédure appelante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
33 Private Function GetNode(pRoot As XmlNode, pNodeName As String) As String Dim CpteurNoeud, CpteurEnfant As Integer Dim NoeudCour As XmlNodeList GetNode = "" NoeudCour = pRoot.SelectNodes("commande") 'Si le noeud de départ existe => on continue If Not NoeudCour Is Nothing Then For CpteurNoeud = 0 To NoeudCour.Count - 1 If GetNode = "" Then 'Si on est sur un noeud simple => on vérifie son nom If Not NoeudCour(CpteurNoeud).HasChildNodes Then 'Si on a trouvé le noeud => on récupère sa valeur et on sort If NoeudCour(CpteurNoeud).Name = pNodeName Then GetNode = NoeudCour(CpteurNoeud).InnerXml Exit For End If 'Si le noeud a des enfants, on vérifie chaque enfant Else For CpteurEnfant = 0 To NoeudCour(CpteurNoeud).ChildNodes.Count - 1 If NoeudCour(CpteurNoeud).ChildNodes(CpteurEnfant).Name = pNodeName Then GetNode = NoeudCour(CpteurNoeud).ChildNodes(CpteurEnfant).InnerXml Exit For End If Next End If Else Exit For End If Next End If End Function
dans ma fonction GetNode, "pRoot.SelectNodes("commande")" me renvoie toujours une liste vide...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Dim readerxml As XmlReader readerxml = XmlReader.Create("C:\Applications\TraitementFichierXML\Fichiers\commande_os.txt") Dim FicXML As New XmlDocument() FicXML.Load(readerxml) Dim root As XmlNode = FicXML.DocumentElement Dim test As XmlNodeList NumeroCommande = GetNode(root, "idcommande")
est-ce que c'est le fait de passer par un XMLReader?
Ca fait 2 jours que je suis dessus et là, je craque!!!
Merci d'avance à ceux qui pourront m'aider.
Bonne journée.
Partager