I palced a XML file into my website and tried to read XML from my another website/local. It worked first, but then suddenly I received an error saying "Object reference not set to instance of an object" and could not solve the problem.
Maybe, I miss an important point or because of my settings of my website holding XML file.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim okuyucu As XmlTextReader = New XmlTextReader("http://www.....net/check.xml")
Dim dokuman As XmlDocument = New XmlDocument()
dokuman.Load(okuyucu)
Dim rss As XmlNode = dokuman.SelectSingleNode("/rss")
Dim title As XmlNodeList = dokuman.SelectNodes("/rss/channel/item/title")
Dim tablo As DataTable = New DataTable()
Dim satır As DataRow
tablo.Columns.Add(New DataColumn("Başlıklar"))
Dim i As Integer
Dim mySonuc As Integer = 0
For i = 0 To 5 - 1 Step i + 1
satır = tablo.NewRow()
satır(0) = title.Item(i).InnerText.ToString()
tablo.Rows.Add(satır)
Next
GridView1.DataSource = tablo
GridView1.DataBind()
End If
End Sub
Specified xPath "rss/channel/item/title" has only 3 nodes in your xml and you are trying to iterate more than 3 times. Thats why Object reference error is raised.
Replace for loop in your code with below one
Dim mySonuc As Integer = 0
For i = 0 To title.Count-1 Step i + 1
satır = tablo.NewRow()
satır(0) = title.Item(i).InnerText.ToString()
tablo.Rows.Add(satır)
Next
ardilo
Member
33 Points
99 Posts
I can not read XML
Dec 23, 2012 06:51 PM|LINK
Dear friends,
I palced a XML file into my website and tried to read XML from my another website/local. It worked first, but then suddenly I received an error saying "Object reference not set to instance of an object" and could not solve the problem.
Maybe, I miss an important point or because of my settings of my website holding XML file.
I've posted XML and the code-block below.
Thanks for your support in advance.
Regards,
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim okuyucu As XmlTextReader = New XmlTextReader("http://www.....net/check.xml") Dim dokuman As XmlDocument = New XmlDocument() dokuman.Load(okuyucu) Dim rss As XmlNode = dokuman.SelectSingleNode("/rss") Dim title As XmlNodeList = dokuman.SelectNodes("/rss/channel/item/title") Dim tablo As DataTable = New DataTable() Dim satır As DataRow tablo.Columns.Add(New DataColumn("Başlıklar")) Dim i As Integer Dim mySonuc As Integer = 0 For i = 0 To 5 - 1 Step i + 1 satır = tablo.NewRow() satır(0) = title.Item(i).InnerText.ToString() tablo.Rows.Add(satır) Next GridView1.DataSource = tablo GridView1.DataBind() End If End SubPrimillo
Star
8725 Points
1678 Posts
Re: I can not read XML
Dec 23, 2012 07:11 PM|LINK
Check out this starter kit, use XML as data store
http://www.asp.net/downloads/starter-kits/small-business
Primillo
http://www.facebook.com/programandopuntonet
PrashanthRed...
Member
559 Points
94 Posts
Re: I can not read XML
Dec 28, 2012 11:48 PM|LINK
Hi,
Specified xPath "rss/channel/item/title" has only 3 nodes in your xml and you are trying to iterate more than 3 times. Thats why Object reference error is raised.
Replace for loop in your code with below one
Dim mySonuc As Integer = 0 For i = 0 To title.Count-1 Step i + 1 satır = tablo.NewRow() satır(0) = title.Item(i).InnerText.ToString() tablo.Rows.Add(satır) NextThanks,
Prashanth Reddy