Jump to content

Generate Xml With Asp


jazzman

Recommended Posts

I have been attempting to query a database using ASP with vbscript and then turning it into a valid XML document. I followed the directions on this page:http://www.w3schools.com/xml/xml_server.asp (4th box down)You can see this attempt on our website here:http://www.jalc.org/rss_create.aspThe error I'm getting makes reference to a <font> tag which doesn't even exist.Here is my code:

<%response.ContentType = "text/xml"set conn=Server.CreateObject("ADODB.Connection")conn.provider="Microsoft.Jet.OLEDB.4.0;"conn.open server.mappath("C:\PEO\JALCdatabases\newsflash.mdb")sql="select * FROM tblNewsflash2 WHERE pdf<>'' ORDER BY releaseDATE DESC"set rs=Conn.Execute(sql)response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")response.write("<Channel>")while (not rs.EOF)response.write("<Item>")response.write("<Title>" & rs("releaseTitle") & "</Title>")response.write("<Link>" &  rs("pdf") & "</Link>")response.write("<Description>" & "</Description>")response.write("</Item>")rs.MoveNext()wendrs.close()conn.close()response.write("</Channel>")%>

Any assistance would be greatly appreciated.Thanks,Andy

Link to comment
Share on other sites

If you "View Source" your generated output, you'll see it looks like:

 <font face="Arial" size=2><p>Microsoft JET Database Engine</font> <font face="Arial" size=2>error '80004005'</font><p><font face="Arial" size=2>Could not find file 'C:\PEO\PEO250\Site\newsflash.mdb'.</font><p><font face="Arial" size=2>/rss_create.asp</font><font face="Arial" size=2>, line 5</font>

So therefore, it appears the path to your mdb file is wrong, or is not accessible to ASP. Check to see if... err... I think it was called "IIS_USR"... has permissions to access the file. Alternatively, simply move the mdb file (manually) into your public folder (in which ASP has permissions by default).

Link to comment
Share on other sites

If the content being pulled from your database has any special characters, your output will break. Research how to incorporate CDATA in your output and see if that helps. Or, ASP may have a xmlformat function you can call - in ColdFusion it would look something like this:

<?xml version='1.0' encoding='ISO-8859-1'?>")<Channel><cfoutput><Item><Title>#xmlformat(releaseTitle)#</Title><Link>#pdf#</Link><Description></Description></Item></cfoutput></Channel>

OR

<?xml version='1.0' encoding='ISO-8859-1'?>")<Channel><cfoutput><Item><Title><![CDATA[#releaseTitle#]]></Title><Link>#pdf#</Link><Description></Description></Item></cfoutput></Channel>

Link to comment
Share on other sites

Thanks for your input. I have done as you recommended. I was able to resolve the path issue. However, when I try and validate it tells me that there is no charset attribute. I have tried adding:

response.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>")

I have tried adding the CDATA tag and that didn't seem to help. Any other ideas?Thanks,Andy

If the content being pulled from your database has any special characters, your output will break. Research how to incorporate CDATA in your output and see if that helps. Or, ASP may have a xmlformat function you can call - in ColdFusion it would look something like this:
<?xml version='1.0' encoding='ISO-8859-1'?>")<Channel><cfoutput><Item><Title>#xmlformat(releaseTitle)#</Title><Link>#pdf#</Link><Description></Description></Item></cfoutput></Channel>

OR

<?xml version='1.0' encoding='ISO-8859-1'?>")<Channel><cfoutput><Item><Title><![CDATA[#releaseTitle#]]></Title><Link>#pdf#</Link><Description></Description></Item></cfoutput></Channel>

Link to comment
Share on other sites

RSS isn't going to become valid with the XHTML DTD... in fact, it won't become "valid" at all, as in XML, "valid" means to have a DTD or Schema, against which it validates. RSS doesn't have a DTD or Schema, and therefore can't become "valid". If you want to check your RSS syntax, you should try the feed validator.

Link to comment
Share on other sites

Thanks for your input. I'm making slow progress here. I am now using this document:http://jalc.org/rss_create.aspOn attempting to validate it is telling me:"Missing namespace for Channel"I have tried to understand precisely what this means by looking at this article:http://validator.w3.org/feed/docs/howto/de...namespaces.htmlThis concept is completely lost on me. Could anyone possibly take a stab at explaining this?Also, this is a list of press releases that I want to make available as an RSS feed. There are a lot of invalid characters in the title and link fields.I have tried to put the <! [CDATA[... at various points but am not sure where this goes in the above code.Thank you again so much for your assistance.

RSS isn't going to become valid with the XHTML DTD... in fact, it won't become "valid" at all, as in XML, "valid" means to have a DTD or Schema, against which it validates. RSS doesn't have a DTD or Schema, and therefore can't become "valid". If you want to check your RSS syntax, you should try the feed validator.
Link to comment
Share on other sites

  • 2 months later...
I have been attempting to query a database using ASP with vbscript and then turning it into a valid XML document. I followed the directions on this page:http://www.w3schools.com/xml/xml_server.asp (4th box down)You can see this attempt on our website here:http://www.jalc.org/rss_create.aspThe error I'm getting makes reference to a <font> tag which doesn't even exist.Here is my code:
<%response.ContentType = "text/xml"set conn=Server.CreateObject("ADODB.Connection")conn.provider="Microsoft.Jet.OLEDB.4.0;"conn.open server.mappath("C:\PEO\JALCdatabases\newsflash.mdb")sql="select * FROM tblNewsflash2 WHERE pdf<>'' ORDER BY releaseDATE DESC"set rs=Conn.Execute(sql)response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")response.write("<Channel>")while (not rs.EOF)response.write("<Item>")response.write("<Title>" & rs("releaseTitle") & "</Title>")response.write("<Link>" &  rs("pdf") & "</Link>")response.write("<Description>" & "</Description>")response.write("</Item>")rs.MoveNext()wendrs.close()conn.close()response.write("</Channel>")%>

Any assistance would be greatly appreciated.Thanks,Andy

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...