CodeAve.com CodeAve.com - ASP - Read/Write
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Create XML Documents from Access Output
Active Server Pages allow for the easy ability to create dynamic views of your data on a web server, but you can also create "static" documents on the server. This can be particularly useful if you wish to distribute your information on CD or in virtually any document form. The following example will utilize our state info db. After reading the contents of the db instead of writing output to the browser html text is written to the server on a file with the .xml file extension.  By placing appropriate XML tags around the Db output the XML document that is created on the server than can be read by the browser or any appropriate means. The current time (server time) is also added to show that all the XML documents is created dynamically.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<html>
<title>CodeAve.com(Create XML from Access)</title>
<body bgcolor="#FFFFFF">
<%
' Name of the access db being queried
accessdb="state_info" 

' Connection string to the access db
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

' Query the states table from the state_info db
sql = "select state,statename,capital,year,order from states order by states.order " 

' Execute the sql
rs.Open sql, cn

' Move to the first record
rs.MoveFirst

' Name for the ouput document 
file_being_created= "states.xml"

' create a file system object
set fso = createobject("scripting.filesystemobject")

' create the text file - true will overwrite any previous files
' Writes the db output to a .xml file in the same directory 
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)

' All non repetitive xml on top goes here
act.WriteLine("<?xml version=""1.0""?>")
act.WriteLine("<states>")

'Loop to output all the query results to the xml document
do while not rs.eof

' counter to give each record a sequential listing
counter=counter+1

act.WriteLine("<state id="""& counter &""">")
act.WriteLine("<state_abbrev>" & rs("state") & "</state_abbrev>" )
act.WriteLine("<state_name>" & rs("statename") & "</state_name>" )
act.WriteLine("<state_capital>" & rs("capital") & "</state_capital>")
act.WriteLine("<year_admitted>"& rs("year") & "</year_admitted>")
act.WriteLine("<order_admitted>"& rs("order") & "</order_admitted>")
act.WriteLine("</state>")

' move to the next record
rs.movenext
loop

' All non repetitive xml on bottom goes here
act.WriteLine("</states>")


' close the object (xml)
act.close


' Writes a link to the newly created xml document in the browser
response.write "<a href='states.xml'>States</a> (.xml) has been created <br>"
response.write "on " & now() & "<br>"
%>

</body>
</html>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3