472,126 Members | 1,448 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

Object reference not set to an instance of an object.

Hello,

I have some code which simply reads a RSS with the
XmlTextReader and XmlDocument. Unfortunaly I get the error:

Object reference not set to an instance of an object.

Here is my simple code:

private function CheckRSS(byval strRSS as string)
Dim reader as new XmlTextReader(strRSS)
Dim xmlDoc as XmlDocument

Try
xmlDoc.Load(reader)
Catch ex As Exception
Response.Write("ERR in Rss File:" & strRSS
& "<br>")
Response.Write("Err: RSS File:" & ex.Message
& "<br>")
Exit Function
End Try

' load only the item nodes
Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")

For Each node As XmlNode In nodes
Try
Dim strPostTitle as string = node
("title").InnerXml
Dim strPost as string = node
("description").InnerXml
Dim strPostURL as string = node
("link").InnerXml
Dim strPostDate as string = node
("pubDate").InnerXml

response.write(strPostTitle & "<br>")
Catch ex As Exception
Response.Write("ERR in loading nodes: " &
ex.Message() & "<br>")
Exit Function
End Try
Next
end function

Can anybody tell me why I get this error?

Thanks
Nov 12 '05 #1
2 8104
Where exactly the error happens?

--
Victor Hadianto
http://synop.com/Products/SauceReader/

"Anonymous" <an*******@discussions.microsoft.com> wrote in message
news:4f****************************@phx.gbl...
Hello,

I have some code which simply reads a RSS with the
XmlTextReader and XmlDocument. Unfortunaly I get the error:

Object reference not set to an instance of an object.

Here is my simple code:

private function CheckRSS(byval strRSS as string)
Dim reader as new XmlTextReader(strRSS)
Dim xmlDoc as XmlDocument

Try
xmlDoc.Load(reader)
Catch ex As Exception
Response.Write("ERR in Rss File:" & strRSS
& "<br>")
Response.Write("Err: RSS File:" & ex.Message
& "<br>")
Exit Function
End Try

' load only the item nodes
Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")

For Each node As XmlNode In nodes
Try
Dim strPostTitle as string = node
("title").InnerXml
Dim strPost as string = node
("description").InnerXml
Dim strPostURL as string = node
("link").InnerXml
Dim strPostDate as string = node
("pubDate").InnerXml

response.write(strPostTitle & "<br>")
Catch ex As Exception
Response.Write("ERR in loading nodes: " &
ex.Message() & "<br>")
Exit Function
End Try
Next
end function

Can anybody tell me why I get this error?

Thanks

Nov 12 '05 #2
XmlDocument xmlDoc is declared, but it is not instantiated(new
XmlDocument()),

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Anonymous" <an*******@discussions.microsoft.com> wrote in message
news:4f****************************@phx.gbl...
Hello,

I have some code which simply reads a RSS with the
XmlTextReader and XmlDocument. Unfortunaly I get the error:

Object reference not set to an instance of an object.

Here is my simple code:

private function CheckRSS(byval strRSS as string)
Dim reader as new XmlTextReader(strRSS)
Dim xmlDoc as XmlDocument

Try
xmlDoc.Load(reader)
Catch ex As Exception
Response.Write("ERR in Rss File:" & strRSS
& "<br>")
Response.Write("Err: RSS File:" & ex.Message
& "<br>")
Exit Function
End Try

' load only the item nodes
Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")

For Each node As XmlNode In nodes
Try
Dim strPostTitle as string = node
("title").InnerXml
Dim strPost as string = node
("description").InnerXml
Dim strPostURL as string = node
("link").InnerXml
Dim strPostDate as string = node
("pubDate").InnerXml

response.write(strPostTitle & "<br>")
Catch ex As Exception
Response.Write("ERR in loading nodes: " &
ex.Message() & "<br>")
Exit Function
End Try
Next
end function

Can anybody tell me why I get this error?

Thanks

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Daniel | last post: by
15 posts views Thread by Carlos Lozano | last post: by
4 posts views Thread by Luke Matuszewski | last post: by
12 posts views Thread by Andrew Poulos | last post: by
6 posts views Thread by Shailen Sukul | last post: by
14 posts views Thread by Philipp Reif | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.