Solved

XML file fails to process correctly

Posted on 2016-08-15
3
58 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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