dom|xml| Server | static | page
Server-Side generated page data, in order to improve access speed, often need to generate static HTM page.
Typically, you can use the FSO to generate static HTM pages.
However, if the FSO is prohibited or does not use the FSO's permissions, you need other methods to solve.
Using XMLDOM, the Save () method is a good way to solve the problem.
Also, if the data is in XML format, using Save () is faster than using the FSO, and the code has a high reuse rate.
However, it should be noted that:
When the Xmldom.save () method is invoked, the default encoding is "Uft-8".
If the specified document output type is "HTML", because it cannot specify the encoding type, and when the data contains Chinese characters, you will find that all the Chinese characters in the stored HTM data become garbled.
Workaround:
Mechanism, typically browsers are not interpreted for HTML-type pages other than the HTM tag.
A. Specify the output document type is "XML"
B. Specify the encoding (encoding= "gb2312")
C. Specify retention indent format (for easy reading)
Examples:
/***create.asp***/
<%
Dimcxmlfile,cxslfile
Dimoxml,xsl
Dimooutput
Dimchtmlfile,coutputfile
Chtmlfile= "Book.htm"
' chtmlfile= ' Book_ ' &replace (replace (now, ":", "),"-"," ")," "," ") &". htm "
Cxmlfile=server.mappath ("Book.xml")
Cxslfile=server.mappath ("book.xsl")
Coutputfile=server.mappath (Chtmlfile)
Setoxml=server.createobject ("Microsoft.XMLDOM")
Oxml.async=false
Oxml.load (Cxmlfile)
Setoxsl=server.createobject ("Microsoft.XMLDOM")
Oxsl.async=false
Oxsl.load (Cxslfile)
Setooutput=server.createobject ("Microsoft.XMLDOM")
Calloxml.transformnodetoobject (Oxsl,ooutput)
Ooutput.save (Coutputfile)
Setoxml=nothing
Setoxsl=nothing
Setooutput=nothing
Response.Redirect (Chtmlfile)
%>
/***book.xml***/
<?xmlversion= "1.0" encoding= "gb2312"
<?xml-stylesheettype= "text/xsl" Book.xsl
<moonpiazza>
<book>
< title > xml-based asp.net development </title
< pricing >42 </
< author >danwahlin/Wang Baoliang </author
</book>
<book>
< title >xml application of UML modeling technology </"
< pricing >32</pricing
< author >davidcarlson/Ivan Zhou Handsome Hou Yimong Shen Jin, etc. </author
</book>
< Book>
< title > Extreme Programming Research </Title
< pricing >70</pricing
< author >giancarriosucci/ michelemarchesi/Zhanghui (translator) </
</book>
<book>
< title >designpatterns</title
< pricing >38</
< author >erichgamma/richardhelm/ralphjohnson/johnvlissides</
</book
</moonpiazza>
/***book.xsl***/
<?xmlversion= "1.0" encoding= "gb2312"?>
<xsl:stylesheetxmlns:xsl= "" version= "1.0" >
<!--The following sentence must be-->
<xsl:outputmethod= "xml" encoding= "gb2312" indent= "yes"/>
<xsl:templatematch= "/" >
<metahttp-equiv= "Content-type" content= "text/html;charset=gb2312"/>
<!--bymoonpiazza2003.6.13-->
<body>
<tableborder= "1" >
<tr>
<xsl:for-eachselect= "moonpiazza/book[position () =1]/*" >
<td><xsl:value-ofselect= "name ()"/></td>
</xsl:for-each>
</tr>
<xsl:for-eachselect= "Moonpiazza/book" >
<tr>
<xsl:for-eachselect= "./*" >
<td><xsl:value-ofselect= "." /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>