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
type=thisNode.SelectSingleNode("//RouteAddr[@type]")
val=thisNode.SelectSingleNode("//RouteAddr").InnerText
type=thisNode.SelectSingleNode("//ns:RouteAddr[@type]",, nsmgr)
val=thisNode.SelectSingleNode("//ns:RouteAddr", , nsmgr).InnerText
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlElement
Try
'Create the XML Document
m_xmld = New XmlDocument()
'Load the Xml file
m_xmld.Load("C:\Documents\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
For temp As Integer = 0 To m_nodelist.Count - 1
MsgBox(m_nodelist(temp).Attributes.GetNamedItem("seqnum").Value)
Dim thisNode As XmlNode = m_nodelist(temp).SelectSingleNode("ns:RoutingInfo", nsmgr)
If thisNode Is Nothing Then
Else
MsgBox(thisNode.OuterXml)
MsgBox(thisNode.SelectSingleNode("//ns:RouteAddr[@type]", nsmgr))
MsgBox(thisNode.SelectSingleNode("//ns:RouteAddr", nsmgr).InnerText)
End If
For Each childnode As XmlNode In m_nodelist(temp)
MsgBox(childnode.Name)
Next
Next
MsgBox(m_nodelist.Count)
Catch ex As Exception
Throw New Exception("Failed to load xml content. " & ex.Message)
End Try
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)
nsmgr.AddNamespace("xsi", "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("//xsi:Call", nsmgr)
"<RequestedAddr type=""unknown"" xmlns=""http://www.metaswitch.com/cfs/billing/V1.0"">12095551212</RequestedAdd r><DestAdd r type=""e164"" xmlns=""http://www.metaswitch.com/cfs/billing/V1.0"">+12095551212</D estAddr><R outedAddr type=""national"" xmlns=""http://www.metaswitch.com/cfs/billing/V1.0"">2095551212</Rou tedAddr><C allingPart yRoutedAdd r type=""national"" xmlns=""http://www.metaswitch.com/cfs/billing/V1.0"">2095551212</Cal lingPartyR outedAddr> <CallingPa rtyOrigAdd r type=""national"" xmlns=""http://www.metaswitch.com/cfs/billing/V1.0"">2095551212</Cal lingPartyO rigAddr>"
OuterXml
<RoutingInfo xmlns=""http://www.metaswitch.com/cfs/billing/V1.0""><RequestedAddr type=""unknown"">12095551212</Reques tedAddr><D estAddr type=""e164"">+12095551212 </DestAddr ><RoutedAd dr type=""national"">20955512 12</Routed Addr><Call ingPartyRo utedAddr type=""national"">20955512 12</Callin gPartyRout edAddr><Ca llingParty OrigAddr type=""national"">20955512 12</Callin gPartyOrig Addr></Rou tingInfo>" String
thisNode.SelectSingleNode("//ns:RoutedAddr[@type]", nsmgr).Value
Open in new window
The node looks like thisOpen in new window
How can i get the Attribute (Type) and Value for <RoutedAddr>