Bonjour à tous,
je cherche à récupérer des informations XML, je suis arrivé à récupérer les attributs par contre les childrens ils ne sont pas récupérés ci-dessous mon code et la forme de mon fichier XML :
XML template :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?xml version="1.0" encoding="utf-8"?> <Root> <ToolsList> <Tool PartNumber="0018B"> <ToolLine Text=" FI : 3897" /> <ToolLine Text=" PINCE1 Reference : M 22520/2.01" /> <ToolLine Text=" Position : 2.02" /> <ToolLine Text=" Reglage : 7" /> <ToolLine Text=" PINCE2 Reference: M 22520/7.01" /> </Tool> </ToolsList> </Root>
Code VB.NET : 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 Imports System.IO Imports System.Xml Module ParsingUsingXmlDocument Sub Main() Try Dim m_xmld As XmlDocument Dim m_nodelist As XmlNodeList Dim m_node As XmlNode 'Create the XML Document m_xmld = New XmlDocument() 'Load the Xml file m_xmld.Load("D:\Users\Desktop\Xml to excel chahine\U881A1013_105_A_PREP_1.xml") m_nodelist = m_xmld.SelectNodes("/Root/ToolsList/PartNumber") 'Loop through the nodes For Each m_node In m_nodelist Dim partnumber = m_node.Attributes.GetNamedItem("PartNumber").Value 'Get the firstName Element Value Dim text1 = m_node.ChildNodes.Item(0).InnerText Dim text2 = m_node.ChildNodes.Item(1).InnerText Dim text3 = m_node.ChildNodes.Item(2).InnerText Dim text4 = m_node.ChildNodes.Item(3).InnerText Console.Write("partnumber: " & partnumber _ & " text1: " & text1 & " text3: " _ & text3) Console.Write(vbCrLf) Next Catch errorVariable As Exception 'Error trapping Console.Write(errorVariable.ToString()) End Try End Sub End Module
si vous avez des idées n'hésitez pas à m'aider, merci en avance
après cette question comment je peux implémenter ces informations sur un fichier Excel
Partager