Results 1 to 4 of 4

Thread: Server Scriting via XML

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    56

    Server Scriting via XML

    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

    Code:
     
    <%
    
    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!

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    56
    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
    ^

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    56
    excellent, thanx for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width