XML file displaying error

G

Guest

hello how ru all,

i have some problem in displaying xml file in asp.net, i successfully create
an xml file but when want to display it through ASP.NET code it throwing
following error.

Unexpected XML declaration. The XML declaration must be the first node in
the document, and no white space characters are allowed to appear before it.
Line 2, position 3.


below i'm providing my xml file creating code:



<%@Page Language="VB"%>
<%@ Import Namespace="System.XML"%>
<script runat="server">
Sub page_load()
Dim strCurrentPath As String = Request.PhysicalPath
Dim strXMLPath As String = Left(strCurrentPath,
InStrRev(strCurrentPath, "\")) & "newxmlfile4.rss"
Dim objXMLWriter As XmlTextWriter
objXMLWriter = New XmlTextWriter(strXMLPath, Nothing)
objXMLWriter.Formatting = Formatting.Indented
objXMLWriter.Indentation = 3
objXMLWriter.WriteStartDocument()
objXMLWriter.WriteStartElement("rss")
objXMLWriter.WriteAttributeString("version", "2.0")
objXMLWriter.WriteStartElement("channel")
objXMLWriter.WriteElementString("title", "Latest content from
www.mysite.com")
objXMLWriter.WriteElementString("link", "http://www.mysite.com")
objXMLWriter.WriteElementString("description", "Get the latest news
from www.mysite.com")
objXMLWriter.WriteElementString("copyright", "© www.mysite.com")
objXMLWriter.WriteElementString("webMaster", "(e-mail address removed)")
objXMLWriter.WriteEndElement()
objXMLWriter.WriteEndElement()
objXMLWriter.Flush()
End Sub
</script>

And follwing is my xml file displaying code :

<%@ Import Namespace="System.XML"%>

<script language=VB runat=SERVER>
Sub Page_Load()
Dim reader As New
XmlTextReader("F:\ASAD\xmlfiles\newxmlfile4.rss")
Dim xml_doc As New XmlDocument()

xml_doc.Load(reader)
fetchXML.Document = xml_doc
</script>

<asp:xml id="fetchXML" runat="server"
TransformSource="RSSReader.xsl"></asp:xml>


pls review on it and tell me where is the problem thanks.
 
G

Guest

Just save the file you generate once, and look at it in a text editor... see
what it looks like.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top