L
Lou
I have a app that gets xml data from a web site using http:
This all works if I test it in VB6, but the ParseXMLFile function
crashes on the line:
nNode = xDoc.SelectSingleNode("cap:alert")
With the error message
"Namespace Manager or XsltContext needed. This query has a prefix, variable,
or user-defined function."
Why does this work in VB6 but not VB .Net?
..Net code
' This causes the round-trip
Dim rsp As WebResponse = req.GetResponse()
sr = New StreamReader(WebResp.GetResponseStream(), True)
myString = sr.ReadToEnd()
ParseXMLFile(myString)
Private Sub ParseXMLFile(ByVal sXML As String)
Dim xDoc As New XmlDocument()
Dim nNode As XmlNode
Dim nNodes As XmlNodeList
xDoc.LoadXml(sXML)
nNode = xDoc.SelectSingleNode("cap:alert")
If Not nNode Is Nothing Then
nNodes = nNode.SelectNodes("cap:info")
If Not nNodes Is Nothing Then
Debug.Print(nNodes.Count.ToString)
End If
End If
End Sub
'VB6 code that works perfectly
Dim nNode As IXMLDOMNode
Dim nNodes As IXMLDOMNodeList
objhttp.Open "GET", "http://www.weather.gov/alerts/al.cap", False
objhttp.send
'this puts the result directly into an xml domdocument
Set xmlDocument = objhttp.responseXML
Debug.Print xmlDocument.xml
Set nNode = xmlDocument.selectSingleNode("cap:alert")
Set nNodes = nNode.selectNodes("cap:info")
This all works if I test it in VB6, but the ParseXMLFile function
crashes on the line:
nNode = xDoc.SelectSingleNode("cap:alert")
With the error message
"Namespace Manager or XsltContext needed. This query has a prefix, variable,
or user-defined function."
Why does this work in VB6 but not VB .Net?
..Net code
' This causes the round-trip
Dim rsp As WebResponse = req.GetResponse()
sr = New StreamReader(WebResp.GetResponseStream(), True)
myString = sr.ReadToEnd()
ParseXMLFile(myString)
Private Sub ParseXMLFile(ByVal sXML As String)
Dim xDoc As New XmlDocument()
Dim nNode As XmlNode
Dim nNodes As XmlNodeList
xDoc.LoadXml(sXML)
nNode = xDoc.SelectSingleNode("cap:alert")
If Not nNode Is Nothing Then
nNodes = nNode.SelectNodes("cap:info")
If Not nNodes Is Nothing Then
Debug.Print(nNodes.Count.ToString)
End If
End If
End Sub
'VB6 code that works perfectly
Dim nNode As IXMLDOMNode
Dim nNodes As IXMLDOMNodeList
objhttp.Open "GET", "http://www.weather.gov/alerts/al.cap", False
objhttp.send
'this puts the result directly into an xml domdocument
Set xmlDocument = objhttp.responseXML
Debug.Print xmlDocument.xml
Set nNode = xmlDocument.selectSingleNode("cap:alert")
Set nNodes = nNode.selectNodes("cap:info")