Creating HTML files using XMLDOM Some friends’ hosts do not support FSO, but they also need to generate HTML files. Isn’t it a bit difficult?
Nowadays, hosts that support ASP generally use Microsoft OS, and these OSes are generally win2kserver and above systems. Even if XMLPARSER is not installed, it will also support XMLparser parser analysis
XMLDOM also has a SAVE method. In this way, we can generate HTML files on hosts that do not have FSO.
First, let me explain it one thing. Pay attention to the normalization of HTML and XML code.
HTML
<inputname=t1>
There is no problem with this, the standard writing method should be <inputname="t1">
But if it is in xml
<inputname=t1> is definitely wrong, because the node attribute value of XML is required to be within quotes.
Also <inputname="t1"> is also wrong, because XML requires a closed node, you can write it as
<inputname="t1"></input>, but <inputname="t1"></Input> is also wrong, because XML is case sensitive
For input, XML node, its TEXT value is empty, so it can be written as <inputname="t1"/>
This complies with the XML specification.
For example, in html, it should be written as <br></br> or <br/> in XML.
Image in html
<imagesrc="test.gif">
Write <imagesrc="test.gif"/> in XML
There are also special characters ",>,<,',&, nodes are not allowed to cross, etc. Let me say so much first. As for the standardization of XML documents, it is not the focus of this article, please refer to the relevant information.
I won't talk about how to use fso to generate an html file. But if you use FSO, your intention is to generate such an HTML file
<html>
<head>
<title>test</title>
<body>
<p><imgsrc="test.gif">
</body>
</html>
I've written less here</HEAD>, for HTML, the browser can tolerate it.
But to generate a document with XML specification, it must be
<html>
<head>
<title>test</title>
</head>
<body>
<p><imgsrc="test.gif"/></p>
</body>
</html>
How to save this XML-formatted document to the server?
dimxmlString
xmlString="<html>"&chr(10)&"<head>"&chr(10)&"<title>test</title>"&chr(10)&"</head>"&chr(10)&"<body>"&chr(10)&"<p><imgsrc="test.gif"/></p>"&chr(10)&"</body>"&chr(10)&"</html>"
dimxmlDoc
setxmlDoc=server.createObject("Msxml2.DOMDocument")
xmlDoc.loadXml(xmlString)
xmlDoc.save(server.mappath("test.htm"))
setxmlDoc=nothing
The xmlDOM.loadXml() method is used here, which loads a piece of XMLDOCUMENT into the object.
This is why you need to write the HTML you are preparing to generate into XML specifications, because the LOADXML() method only supports text strings that comply with XML specifications.