Question retrieving information XML & copy to excel Files

Status
Not open for further replies.

dev_psychos

New member
Joined
Jun 19, 2019
Messages
1
Programming Experience
Beginner
Hello has all,

I seek to retrieve XML information, I arrived a retrieve attributes however the childrens they are not recover my code below and the shape of my XML file:

XML template:
XML:
<? xml version="1.0" encoding="utf - 8"? >

<Root>
    <ToolsList>
        <Tool PartNumber="0018B">
            <ToolLine Text="FI: 3897" />
            <ToolLine Text="PINCE1 Reference: 22520/2.01 M" />
            <ToolLine Text="Position: 2.02" />
            <ToolLine Text="setting: 7" />
            <ToolLine Text="PINCE2 Reference: 22520/7.01 M" />
        </Tool>
    </ToolsList>
</root>
c# code:
VB.NET:
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
            = New m_xmld XmlDocument()
            ' Load the Xml file
            m_xmld. Load ("D:\Users\Desktop\Xml to excel chahine\U881A1013_105_A_PREP_1.xml")
            = m_xmld m_nodelist. SelectNodes("/Root/ToolsList/PartNumber")
            
            ' Loop through the nodes
            For Each m_node In m_nodelist
                partnumber = m_node. Attributes.GetNamedItem ("PartNumber"). Value
                ' Get the firstName Element Value
                text1 = m_node. ChildNodes.Item (0). InnerText
                text2 = m_node. ChildNodes.Item (1). InnerText
                
                Dim text3 = m_node. ChildNodes.Item (2). InnerText
                
                text4 = m_node. ChildNodes.Item (3). InnerText
                Console.Write("partnumber:" & partnumber _
                & "text1:" & text1 & "text3:" _
                & text3)
                Console.Write (vbCrLf)
            Next
        Catch errorVariable ACE Exception
            ' Error trapping
            Console.Write (errorVariable.ToString ())
        End Try
    End Sub
End Module
if you have any ideas please don't help me, thank you in advance
icon_smile.gif


After a question how I implemented this information on an Excel file
 
Last edited by a moderator:
I have translated your post to English. Please only post in English on this site in future.

I have formatted your code snippets for readability. Please always format code snippets.

Your code is not C#. It is VB.NET. We have a sister site dedicated to VB so you should ask your question there instead. There is a link at the top of the page. Please ensure that you post in English and format code snippets there too.
 
Status
Not open for further replies.

Latest posts

Back
Top Bottom