XML Getting Started Tutorial: XML on the server

Source: Internet
Author: User
Tags sql version
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.