YouTip LogoYouTip

Xml Server

* * * XML files are plain text files similar to HTML files. XML can be easily stored and generated through standard web servers. * * * ## Storing XML Files on the Server The way XML files are stored on an Internet server is exactly the same as HTML files. Open Windows Notepad and write the following lines: ```xml Jani Tove Remember me this weekend ``` Then save this file on your web server with an appropriate filename, such as "note.xml". * * * ## Generating XML via 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 your web server: ```asp <% response.ContentType = "text/xml" response.Write("") response.Write("") response.Write("Jani") response.Write("Tove") response.Write("Remember me this weekend") response.Write("") %> ``` Note that the content type of this response must be set to "text/xml". ( If you want to learn ASP, please find the ASP tutorial on our ( * * * ## Generating XML via PHP To generate an XML response from the server using PHP, use the following code: ```php <?php header("Content-type: text/xml"); echo ""; echo ""; echo "Jani"; echo "Tove"; echo "Remember me this weekend"; echo ""; ?> ``` Note that the content type in the response header must be set to "text/xml". ( If you want to learn PHP, please find the PHP tutorial on our ( * * * ## Generating XML from a Database XML can be generated from a 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 your web server: ```asp <% 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) response.Write("") response.Write("") While Not rs.EOF response.Write("") response.Write("" & rs("fname") & "") response.Write("" & rs("lname") & "") response.Write("") rs.MoveNext() Wend rs.Close() conn.Close() response.Write("") %> ``` ( The above example uses ASP with ADO. If you want to learn ASP and ADO, please find the relevant tutorials on our ( * * * ## Transforming XML into XHTML on the Server Using XSLT The following ASP code transforms an XML file into XHTML on the server: ```asp ``` Explanation of the example: * The first code block creates an instance of Microsoft's XML parser (XMLDOM) and loads the XML file into memory. * The second code block creates another instance of the parser and loads the XSL file into memory. * Finally, the last line uses the XSL document to transform the XML document and sends the result as XHTML to your browser. ( * * * ## Saving XML as a File via ASP This ASP example creates a simple XML document and saves it to the server: ```asp <% text = "" text = text & "Tove" text = text & "Jani" text = text & "Reminder" text = text & "Don't forget me this weekend!" text = text & "" Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM") xmlDoc.Async = False xmlDoc.LoadXML(text) xmlDoc.Save("test.xml") %> ```
← Xml Dom AdvancedXml Encoding β†’