Since XML was designed to transport and store data, it is crucial that XML be easily stored and generated by a standard web server. Actually that is what the case in fact is. XML can easily be stored and generated by a standard web server. However, to go through this short article, you need to have knowledge of ASP and PHP. Additionally, XML can be generated on a server without any installed XML software. To generate an XML response from the server – simply write the following code and save it as an ASP file on the web server:
1 2 3 4 5 6 7 8 9 |
<% response.ContentType="text/xml" response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>") response.Write("<note>") response.Write("<from>Jane</from>") response.Write("<to>Doe</to>") response.Write("<message>Remember me this weekend</message>") response.Write("</note>") %> |
Note that the content type of the response must be set to “text/xml”. Further, to generate an XML response from the server using PHP, use following code:
1 2 3 4 5 6 7 8 9 |
<?php header("Content-type: text/xml"); echo "<?xml version='1.0' encoding='ISO-8859-1'?>"; echo "<note>"; echo "<from>Jane</from>"; echo "<to>Doe</to>"; echo "<message>Remember me this weekend</message>"; echo "</note>"; ?> |
Once again, the content type of the response header must be set to “text/xml”. Other than being stored and manipulated on the server side, XML can also be transformed into XHTML file on the server side. Following ASP code can be sued to server this purpose:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<% 'Load XML set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("simple.xml")) 'Load XSL set xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath("simple.xsl")) 'Transform file Response.Write(xml.transformNode(xsl)) %> |
In the above example:
XML is a bit advanced compared to HTML but it certainly contains a lot more advantages when it comes to web programming.