PDA

Click to See Complete Forum and Search --> : Server Scriting via XML


MavsteR
Apr 28th, 2004, 07:57 AM
Hi, getting a small error with some of my code, just wondered if anyone knew where i was going wrong. Basically all i want it to do is if there are no records within the database, for it to write a statement saying just this. Is this possible with XML declerations in the coding... The code that i have at the moment is as follows


<%

response.ContentType = "text/xml"

Set ObjConn = Server.CreateObject("ADODB.Connection")
ObjConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("xml.mdb")
ObjConn.Open

sql="SELECT * FROM Fishing"

set rs=ObjConn.Execute(sql)

if rs.BOF and rs.EOF then

response.write("No Products Matching That Description")

else

rs.MoveFirst()

response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")

response.write("<FatherGifts>")

while (not rs.EOF)

response.write ("<Fishing>")

response.write("<FishName>" & rs("FishName") & "</FishName>")
response.write("<FishPrice>" & rs("FishPrice") & "</FishPrice>")
response.write("<FishDesc>" & rs("FishDesc") & "</FishDesc>")

response.write ("</Fishing>")

rs.MoveNext()

wend

response.write("</FatherGifts>")

end if

rs.close()

ObjConn.close()

%>


Any help would be much appriciated!

MavsteR
Apr 28th, 2004, 08:00 AM
lol sorry i forgot to post the error which is...

Invalid at the top level of the document. Error processing resource 'http://mmtprojects.herts.ac.uk/year4/mmt4-30/XML%20Group%2047/fish.asp'. Line 1, Position 1

No Products Matching That Description
^

techgnome
Apr 28th, 2004, 09:26 AM
that's because you've already sent out an XML header: response.ContentType = "text/xml"

To avoid this, you need to wrap the error msg within XML tags.
response.write("<error>No Products Matching That Description</error>")

TG

MavsteR
Apr 28th, 2004, 09:30 AM
excellent, thanx for the help!