?
Solved

XML file fails to process correctly

Posted on 2016-08-15
3
Medium Priority
?
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

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 63

Accepted Solution

by:
Fernando Soto earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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