Save XML File on Server
When you create an XML file and display it on your browser, you may want ot
save it on your server. There is a simple way to save your XML file. If you
created an XML file and displayed on your brower, you may directly go to "View"
> "Source", and then save the source code of the XML file to your
local computer.
Or you can use XML DOM to save it on your server. The following example shows
how to use ASP to save an XML file on the server:
<%
text="<email>"
text=text & "<to>John</to>"
text=text & "<from>Michael</from>"
text=text & "<subject>Hi</subject>"
text=text & "<body>Hello my friend!</body>"
text=text & "</email>"
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(text)
xmlDoc.Save("email.xml")
%>
The third method to save an XML file is using Filesystem Functions to write
and save an XML file. The following is an example using PHP:
<?php
$text ='<?xml version="1.0" encoding="UTF-8"?>';
$text .='<GPS>';
$text .='<Item>';
$text .='<name>TomTom XL 330S 4.3-Inch Touchscreen Traffic-Ready Portable
GPS Navigator</name>';
$text .='<price>$299.95</price>';
$text .='<link>http://www.selectagps.com/TomTom-XL-330S-4-3-Inch-Touchscreen-Traffic-Ready-Portable-GPS-Navigator-Electronics--d_B0016ORQDI.html</link>';
$text .='</Item>';
$text .='</GPS>';
$file = fopen('gps.xml', 'w');
fwrite($file, $text);
fclose($file);
?>
As you can see, we don't have to use DOM and XSLT to create an XML file and
save it on the server.
|