xml| Server | tutorials | Getting Started Tutorial
XML can be generated on the server side without installing any XML controls.
Storing XML on the server
The XML file can be stored on the server, and the HTML file is stored exactly the same way.
Start Windows Notepad and write the following line of code:
<?xml version= "1.0" encoding= "iso-8859-1"?><note> <from>Jani</from> <to> Tove</to> <message>remember me this weekend</message></note>
Then name the file "Note.xml" and save it on your server.
Generating XML from ASP
XML can be generated on the server side without installing any XML software.
To generate an XML response from the server-simply write the following code and save it as an ASP file on the 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 this response must be set to ' Text/xml '.
If you don't know how to write an ASP, please visit our ASP tutorial.
Getting XML from a database
XML can be generated from the database without installing any XML software.
To generate an XML database response from the server, simply write the following code and save it as an ASP file on the server:
<%response. ContentType = "Text/xml" Set Conn=server.createobject ("ADODB. Connection ") conn.provider=" microsoft.jet.oledb.4.0; " Conn.Open Server.MapPath ("/db/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 () Wendrs.close () Conn.close () Response.Write ("</guestbook>")%>
The example above uses an ASP with ADO. If you don't know how to use ADO, please visit our ADO tutorial.