Use xmldom to generate static html pages on the server side

黄舟
Release: 2017-03-06 16:43:31
Original
1693 people have browsed it

In order to improve the access speed for page data generated on the server side, it is often necessary to generate static htm pages.
Usually, you can use fso to generate static htm pages.
But if fso is banned or does not have permission to use fso, other methods are needed to solve it.
Using xmldom and using its save() method is a good solution.
Moreover, If the data is in xml format, using save() is faster than using fso, and the code reuse rate is also high.

But it should be noted that:
When calling the xmldom.save() method, the default encoding method is "uft-8".
If the specified document output type is "html", due to its The encoding type cannot be specified. When the data contains Chinese characters, you will find that all Chinese characters in the saved htm data have become garbled characters.

Solution:
mechanism, usually the browser does not accept the html type The page will not interpret tags other than htm tags.
a. Specify the output document type as "xml"
b. Specify encoding (encoding="gb2312")
c. Specify to retain indentation Format (for easy reading)

examples:
/*** create.asp ***/
<%
dim cXMLFile, cXSLFile
dim oXML, XSL
dim oOutput
dim cHtmLFile, cOutputFile

cHtmLFile = "book.htm"
&#39;cHtmLFile = "book_" & replace( replace( replace (now,":",""), "-", ""), " ", "") & ".htm"
cXMLFile = Server.MapPath("book.xml")
cXSLFile = Server.MapPath("book.xsl")
cOutputFile = Server.MapPath(cHtmLFile)
Set oXML = Server.CreateObject("Microsoft.XMLDOM") 
oXML.async = false
oXML.load(cXMLFile)
Set oXSL = Server.CreateObject("Microsoft.XMLDOM")
oXSL.async = false
oXSL.load(cXSLFile)
Set oOutput = Server.CreateObject("Microsoft.XMLDOM")
Call oXML.transformNodeToObject(oXSL, oOutput)
oOutput.save (cOutputFile)
Set oXML = Nothing
Set oXSL = Nothing
Set oOutput = Nothing
Response.redirect(cHtmLFile)
%>
/*** book.xml ***/
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl"?>
<moonpiazza>
<book>
      <书名>基于XML 的 asp.net开发</书名>
   <定价>42</定价>
      <作者>Dan Wahlin/王宝良</作者>
</book>
<book>
      <书名>XML应用的UML建模技术</书名>
      <定价>32</定价>
      <作者>David Carlson/周靖 侯奕萌 沈金河等</作者>
</book>
<book>
      <书名>极限编程研究</书名>
      <定价>70</定价>
      <作者>Giancarrio Succi/Michele Marchesi/张辉(译)</作者>
</book>
<book>
      <书名>Design Patterns</书名>
      <定价>38</定价>
      <作者>Erich Gamma/Richard Helm/Ralph Johnson/John Vlissides</作者>
</book>
</moonpiazza>
/*** book.xsl ***/
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- 下面一句必须 -->
<xsl:output method="xml" encoding="gb2312" indent="yes"/>
<xsl:template match="/">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- by moonpiazza 2003.6.13-->
<body>
<table border="1">
  <tr>
   <xsl:for-each select="moonpiazza/book[position()=1]/*">    
    <td><xsl:value-of select="name()" /></td>    
   </xsl:for-each>
  </tr>
  <xsl:for-each select="moonpiazza/book">
   <tr>
    <xsl:for-each select="./*">    
     <td><xsl:value-of select="." /></td>    
    </xsl:for-each>
   </tr>
  </xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Copy after login

The above is the content of using xmldom to generate static html pages on the server side. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!