Solved

XML file fails to process correctly

Posted on 2016-08-15
3
42 Views
Last Modified: 2016-08-16
I have an XML file which i am trying to process and for some reason it just doesn't work correctly

The code i use to test is

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Try
            Dim m_xmld As XmlDocument
            Dim m_nodelist As XmlNodeList
            Dim m_node As XmlElement
            'Create the XML Document
            m_xmld = New XmlDocument()
            'Load the Xml file
            m_xmld.Load("C:\Users\public\Documents\sample2.xml")

            'Get the list of name nodes 
            m_nodelist = m_xmld.SelectNodes("File/CDRs/Call")
            'Loop through the nodes


            MsgBox(m_nodelist.Count)
        Catch errorVariable As Exception
            'Error trapping
            Console.Write(errorVariable.ToString())
            Console.ReadLine()
        End Try

    End Sub

Open in new window

sample2.xml
0
Comment
Question by:AlexPonnath
  • 2
3 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41756825
Your XML document is using XNamespace which you are not using in your code.
0
 

Author Comment

by:AlexPonnath
ID: 41757105
What would i have to change in my code to use the XNamespace ?
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41757247
Here Alex, try it this way and see if you get results.
Imports System.Xml
Imports System.Xml.XPath

Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlElement

'Create the XML Document
m_xmld = New XmlDocument()
'Load the Xml file
m_xmld.Load("sample2.xml")

'' Added these two lines
Dim nsmgr = New XmlNamespaceManager(m_xmld.NameTable)
nsmgr.AddNamespace("ns", "http://www.metaswitch.com/cfs/billing/V1.0")

'Get the list of name nodes
'' Modified your XPath and added the second parameter 
m_nodelist = m_xmld.SelectNodes("/ns:File/ns:CDRs/ns:Call", nsmgr)
'Loop through the nodes


MsgBox(m_nodelist.Count)

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now