PC Review


Reply
Thread Tools Rate Thread

Can't load XML data

 
 
Lou
Guest
Posts: n/a
 
      15th Feb 2007
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")


 
Reply With Quote
 
 
 
 
Patrick Steele
Guest
Posts: n/a
 
      16th Feb 2007
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
> 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."


You need to add the defined "cap" namespace to the XmlDocument object.
Something like this should work:

xDoc.NameTable.Add("cap")
Dim ns As XmlNamespaceManager = new XmlNamespaceManager(xDoc.NameTable)
ns.AddNamespace("cap", "http://www.incident.com/cap/1.0")

--
Patrick Steele
http://weblogs.asp.net/psteele
 
Reply With Quote
 
Lou
Guest
Posts: n/a
 
      16th Feb 2007
Thank Pat, I just tried that, now I get the same error:
{"Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function."}

Here is my code
Dim sXML as string="http://www.weather.gov/alerts/al.cap"
Dim xDoc As New XmlDocument()

Dim nNode As XmlNode

Dim nNodes As XmlNodeList

xDoc.NameTable.Add("cap")

Dim ns As XmlNamespaceManager = New XmlNamespaceManager(xDoc.NameTable)

ns.AddNamespace("cap", "http://www.incident.com/cap/1.0")



xDoc.LoadXml(sXML)



'THIS IS THE :INE THAT CRASHES

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



"Patrick Steele" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <(E-Mail Removed)>,
> (E-Mail Removed) says...
>> 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."

>
> You need to add the defined "cap" namespace to the XmlDocument object.
> Something like this should work:
>
> xDoc.NameTable.Add("cap")
> Dim ns As XmlNamespaceManager = new XmlNamespaceManager(xDoc.NameTable)
> ns.AddNamespace("cap", "http://www.incident.com/cap/1.0")
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele



 
Reply With Quote
 
Patrick Steele
Guest
Posts: n/a
 
      16th Feb 2007
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
>
> 'THIS IS THE :INE THAT CRASHES
>
> nNode = xDoc.SelectSingleNode("cap:alert")


Doh!! Sorry. Now that's you've got that namespace manager, you need to
pass it to your queries:

nNode = xDoc.SelectSingleNode("cap:alert", ns)

Have fun with that stuff. I wrote a compact framework app that queried
that data from my phone so I can check out any severe weather alerts in
the area.

--
Patrick Steele
http://weblogs.asp.net/psteele
 
Reply With Quote
 
Lou
Guest
Posts: n/a
 
      3rd Mar 2007
Thanks. That worked great!

"Patrick Steele" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <(E-Mail Removed)>,
> (E-Mail Removed) says...
>>
>> 'THIS IS THE :INE THAT CRASHES
>>
>> nNode = xDoc.SelectSingleNode("cap:alert")

>
> Doh!! Sorry. Now that's you've got that namespace manager, you need to
> pass it to your queries:
>
> nNode = xDoc.SelectSingleNode("cap:alert", ns)
>
> Have fun with that stuff. I wrote a compact framework app that queried
> that data from my phone so I can check out any severe weather alerts in
> the area.
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
load list data Souris Microsoft Excel Programming 1 8th Jan 2008 02:04 PM
Using assembly.load to load system.data Dan Microsoft Dot NET Compact Framework 23 4th Mar 2005 10:41 PM
User cannot load Data Access Page....fails to bind data. =?Utf-8?B?bWNuZWFs?= Microsoft Access VBA Modules 0 24th Nov 2004 05:37 PM
load data Microsoft Access Form Coding 1 4th Oct 2004 06:44 PM
Re: Query Data from Table and Load data in different controls Newbie Microsoft Access Queries 0 7th Jul 2004 03:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:46 AM.