I'm trying to populate a table with an XML file however i keep getting the error:
System.Xml.XmlException: The data at the root level is invalid. Line 1, position 1
I've done some googling but didn't find much out on the cause. A lot of people pointed to making sure the folder has anonymous access (which it does), so i'm not sure what else to try. I'll post a bit of code for your viewing pleasure. (keep in mind this is my first work with xml, so the easiest solution, may in fact be the correct one)
===========
news.xml
===========
<?xml version="1.0" encoding="utf-8" ?>
<news>
<article>
<title>My First XML News!</title>
<link>
http://localhost/NewCatSite/news/7-8-2005</link>
<description>An in-depth article about the perils of XML</description>
<summaryImageTitle>Article
Image</summaryImageTitle>
<summaryImageURL>
http://localhost/NewCatSite/images/news/mini/tester.jpg</su
mmaryImage
URL>
<pubDate>Mon 11 Jul 2005 9:45:00 EST</pubDate>
</article>
</news>
**************************
**********
**********
**********
**********
===============
SamplePage.aspx.vb (Sub_Load method only)
===============
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim reader As New XmlTextReader(New StringReader("
http://localhost/NewSite/NewsArticles/news.xml"))
Dim sb As New StringBuilder()
Dim localName As String
Dim title As String
Dim link As String
Dim description As String
Dim sumImgTitle As String
Dim sumImgURL As String
Dim pubDate As String
Dim data As String
reader.WhitespaceHandling = WhitespaceHandling.None
reader.Read() '<<<<>>>>************* This is the line the errors occurs on
While Not reader.LocalName.Equals("N
ews")
reader.Read()
While Not reader.LocalName.Equals("i
tem")
localName = reader.LocalName
reader.Read()
data = reader.ReadString
If localName.Equals("title") Then
title = data
ElseIf localName.Equals("link") Then
link = data
ElseIf localName.Equals("descript
ion") Then
description = data
ElseIf localName.Equals("summaryI
mageTitle"
) Then
sumImgTitle = data
ElseIf localName.Equals("summaryI
mageURL") Then
sumImgURL = data
ElseIf localName.Equals("pubDate"
) Then
pubDate = data
End If
End While
reader.Read()
End While
reader.Close()
End If
End Sub
**************************
**********
**********
**********
**********
******
The plan after getting this done was to use a stringbuilder to append all the data, and add it to a literal control inside SamplePage.aspx. Any ideas on how to get this stuff read in without getting this error?
Thanks
-Matt