Detailed sample code for XML data exchange

黄舟
Release: 2017-03-29 15:48:45
Original
2018 people have browsed it

No need to install XMLcontrol to create XML documents on the server.

-------------------------------------------------- ------------------------------------

Storing XML documents on the server side
XML files can be stored in a web server.

Just like other HTML files, XML files can be stored on a web server.

Open your notepad and write the following code:

<?xml version="1.0" encoding="gb2312"?>
<note><from>小奀</from><to>小林</to><message>晚上一起去火锅呀</message></note>
Copy after login

Then save this file to your server and name it "note.xml".

Note: This XML file must be in the same directory as your other HTML files, and the MIME type should be set to text/xml.

-------------------------------------------------- ------------------------------------

USEASP Generating XML files
XML files can be generated on the server side even if XML software is not installed.

In order for the server to generate a dynamic XML response to the client, we can create a simple ASP page containing the following code on the server:

<%
response.ContentType="text/xml"
response.Write("<?xml version=&#39;1.0&#39; encoding=&#39;gb2312&#39;?>")
response.Write("<note>")
response.Write("<from>小奀</from> ")
response.Write("<to>小林</to>")
response.Write("<message>晚上一起去火锅呀</message> ")
response.Write("</note>")
%>
Copy after login

Note: The content of the XML must be set correct. Check the ASP page. If the server supports ASP, you will see that the displayed content is the same as the note.xml file.

-------------------------------------------------- ------------------------------------

Generate XML document from database
You can dynamically export XML documents from the database without installing any XML software.

We can obtain data from the database by slightly modifying the previous example.

The following is an example of an ASP page that dynamically generates XML data on the server side:

<%
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=&#39;1.0&#39; encoding=&#39;ISO-8859-1&#39;?>")
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>")
%>
Copy after login

The above is the detailed content of Detailed sample code for XML data exchange. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!