0

I need to download an xml file from web, read it and insert the data into MS SQL server table.

I was quite successful using this guide (VBA + Access forms)

Unfortunately, I cannot use this solution as the client would need to have MS Access (doesn't work in runtime mode for some reason) installed and even then with VBA I have some other issues and so on.

Is there anyone that can help me convert this code to VB.net - I'm building a small app in Visual Studio. I have even tried from scratch but this XML is a bit strange.

EDIT: Thanks to rskar, i have tried from the link he provided and thus far was able to repeat the results from the example xml but i cannot do for my xml. My progress bellow (ignore some of the comments from source code sample):

Public 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("C:\CurrencyImport\Temp\eurofxref-daily.xml")
        'Get the list of name nodes 
        m_nodelist = m_xmld.SelectNodes("/gesmes:Envelope/Cube/Cube/Cube")
        'Loop through the nodes
        For Each m_node In m_nodelist
            'Get the Gender Attribute Value
            Dim genderAttribute = m_node.Attributes.GetNamedItem("currency").Value



            MsgBox(genderAttribute)
        Next
    Catch errorVariable As Exception
        'Error trapping
        Console.Write(errorVariable.ToString())
    End Try
End Sub

EDIT: When I "cleaned" the original xml of the node "gesmes:envelope" and changed the m_nodelist = m_xmld.SelectNodes("/Cube/Cube/Cube") like so, it works but i can't get it to work with the original xml ... Probably something with the sintax of the node path.

SOLUTION: this is a solution for the xpath: m_nodelist = m_xmld.SelectNodes("//*[@currency]"). Didn't find any other way to get it working with the original file.

Community
  • 1
  • 1
DAMS
  • 1
  • 1
  • 4
  • Show what did you tried – Fabio Jun 07 '15 at 12:02
  • "Is there anyone that can help me convert this code...?" That sort of question really isn't what Stackoverflow is about. Just google/bing/duckduckgo/whatever on "how to parse xml in vb.net", and you'll find plenty of examples to learn from. Here's a good primer: http://www.codeproject.com/Articles/4826/XML-File-Parsing-in-VB-NET. – rskar Jun 07 '15 at 12:36
  • Fabio, i have successfully done this via VBA as i said, tried almost all tutorials and just couldn't manage to parse through the xml with vb.net. Don't have much experience with Visual Studio. Thanks rskar for the, link ... the only one i guess i haven't try so far - still trying with this one. Perhaps stackoverflow isn't a place to ask these kind of questions, but many times (helped me as well) some one would post a half baked attempt and someone else would help out ... so i was hoping. Still trying my best, if I'm successful, I'll post my answer. – DAMS Jun 07 '15 at 13:41

0 Answers0