Please visit our sponsors !
A Simple XML Server
XML can be generated on a server without any installed XML
controls.
Storing XML on the Server
XML files can be stored on your Internet server.
XML files can be stored on your Internet server, just like any other HTML
files.
Start up your Notepad editor and write the following lines:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<from>Jani</from>
<to>Tove</to>
<message>Remember me this weekend</message>
</note>
|
All you have to do is to save the file on your Internet server with a proper
name like "note.xml", before the XML document is ready to use.
Note: The XML file must be in the same directory (folder) as your HTML
files, and the MIME type of XML files should be set to text/xml.
Generating XML with ASP
XML can be generated on a server without any installed XML software.
To generate an XML response from your server - simply write the
following code and save it as an ASP file on your web server :
<%
response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.Write("<note>")
response.Write("<from>Jani</from>")
response.Write("<to>Tove</to>")
response.Write("<message>Remember me this weekend</message>")
response.Write("</note>")
%>
|
Note that the content type of the response must be set to XML.
See how the ASP file will be returned from
the server.
(ASP stands for Active Server Pages. If you don't know how to write ASP, you
can study it in our ASP
Tutorial)
Getting XML from a Database
XML can be generated from a database without any installed XML software.
The XML response from the previous example can easily be modified to fetch
its data from a database.
To generate an XML database response from the server, simply write the
following code and save it as an ASP file:
<%
response.ContentType = "text/xml"
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0;"
conn.open server.mappath("../ado/database.mdb")
sql="select fname,lname from tblGuestBook"
set rs=Conn.Execute(sql)
rs.MoveFirst()
response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.write("<guestbook>")
while (not rs.EOF)
response.write("<guest>")
response.write("<fname>" & rs("fname") & "</fname>")
response.write("<lname>" & rs("lname") & "</lname>")
response.write("</guest>")
rs.MoveNext()
wend
rs.close()
conn.close()
response.write("</guestbook>")
%>
|
See the real life database output
from this page.
The example above uses ASP with ADO. If you don't know how to use ADO, you
can study it in our ADO tutorial.
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|