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>
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='1.0' encoding='gb2312'?>") response.Write("<note>") response.Write("<from>小奀</from> ") response.Write("<to>小林</to>") response.Write("<message>晚上一起去火锅呀</message> ") response.Write("</note>") %>
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='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 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!