A simple XML server

Source: Internet
Author: User
Tags sql version
xml| Server

XML can be generated on a server that does not have any XML controls installed.

Storing XML on the server

The XML file can be stored on your Internet server. The XML file can be stored on your Internet server, just like any other HTML file.
Open the Notepad editor and write the following lines:

< XML version= "1.0"?>
< note>
< from>jani</from>
< to>tove</to>
< Message>remember me this weekend</message>
</note>

You just need to use an appropriate name such as "Note.xml" to store the file on your Internet server, and then the XML document will be available. Note: The XML file must be in the same path (folder) as your HTML file, and the MIME type of the XML file should be set to Text/xml.

Generating XML with ASP

XML can be generated on a server that does not have any XML software installed. To generate an XML response from your server-just write the following code and save it on your Web server as an ASP file:

<%
Response.contenttype= "Text/xml"


Response.Write ("< XML version= ' 1.0 '?>")
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: The content type of the response must be set to XML. Click here to see how to return ASP files from the server. (ASP represents the Active Server page.) If you don't know how to write ASP, you can learn on W3Schools ' ASP School



Get XML from a database



XML can be generated from a database that does not have any XML software installed. The XML response in the previous example can easily be modified to retrieve its data from a database. To generate an XML database response from a database, you only need to 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 '?>")
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>")
%>

You can try the actual database output for this page yourself. The example above uses an ASP with ADO. If you don't know how to use ADO, you can learn in W3Schools ' ADO School.




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.