SoFunction
Updated on 2025-04-13

Asp generates RSS class_Add RSS to the website page 2/2


1. You must figure out what is needed in the end

Through asp or other dynamic programming languages, what we ultimately need is XML format data, which has nothing to do with the file carrier where the XML data is located. It can be a real XML file, such as: /rss_1.xml. It can also be an asp document, such as: /Blog/

They are all manifestations of XML data. In order to realize the dynamics of XML data, it is necessary to use dynamic programming languages, such as ASP, to generate it.

2. How to generate dynamic XML documents

If you are generating XML files, the dynamic document is in ASP format, so you must use FSO to generate XML files, such as:

The following is a quoted snippet:
<%
xmlfile=("")
Set fso = CreateObject("")
Set MyFile = (xmlfile,True)
("<?xml version=""1.0"" encoding=""gb2312""?>")
("<world>")
("<Hello>hello,world</Hello>")
("</world>")

%>

<a href="">View XML file content</a>

If you are using the generation of dynamic XML data files, you can control the name and value of the XML node in the dynamic document through program means.

3. How to use dynamic documents to generate XML data

If you are not generating an XML file and directly outputting XML data on a dynamic document, you must declare the file type (i.e.)

<% = "text/XML"%>

For example, browse the following dynamic ASP document and display it as an XML data tree in the browser.

The following is a quoted snippet:
<%
With Response
.ContentType = "text/XML"
.write("<?xml version=""1.0"" encoding=""gb2312""?>")
.write("<world>")
.write("<hello,world</hello>")
.write("</world>")
End with
%>


The advantage of the generated XML file is that the document that processes the XML data can be a static document. For example, HTML files parse XML through javascript and XMLDOM, and are also easy to retain data. The dynamic XML data on dynamic documents is not like this. However, in today's era of dynamic documents being used everywhere, it seems that this advantage has no effect on some applications. In fact, the XML data flow of dynamic documents has more advantages: more timely and dynamic.

4. Is this how it works when generating XML data?

Whether it is by generating specific XML files or dynamic XML data streams, just output the relevant XML nodes and values ​​in the XML format. This seems that XML seems very simple. But this does not really touch on XML operations. In our opinion, these XMLs are nothing more than data records composed of pairs of tags and related characters, and have no vitality. However, in fact, operating XML through XMLDOM shows the absolute advantage of XML (this advantage is not obvious when generating XML, but experiences unlimited when adding and deleting XML nodes).

Use XMLDOM to create XML documents, you can use the Save method to generate XML documents, use the createElement method to create XML elements, and createNode to create nodes. In fact, you can choose any one of them for the creation of any tag in XML. However, generally use createElement to create top-level (root) elements, and use createNode to create child nodes (elements). Of course, the usage methods of createElement and createNode are also different.


The following is a quoted snippet:
<%
Set objXMLdoc = CreateObject("")
Set world=("world")
(world)
Set hello=("element", "Hello", "")
= "hello,world"
(hello)
("")
Set objXMLdoc = Nothing
%>

CreateObject("") declares the use of XMLDOM objects
When an element or node is created (createElement, createNode), it is not added to the file tree. To add a node to the file tree, it needs to be inserted, such as appendChild.
(type, name, nameSpaceURI) represents the creation of a new node with a specified type, name, and namespace
type is used to confirm the node type to be established, name is a string to confirm the name of the new node, and the namespace prefix is ​​selective. nameSpaceURI is a string that defines the namespace URI. If the prefix is ​​included in the name parameter, this node is created with the specified prefix in the text of nameSpaceURI. If the prefix is ​​not included, the specified namespace is considered as a preset namespace.
("element", "Hello", "") is equivalent to ("Hello")
4. (hello) is actually the node building under the root element of the XML document. In this case, it is equivalent to (hello), world is the node name in this case, and so on.
So you can write this way:


The following is a quoted snippet:
<%
Set objXMLdoc = CreateObject("")
Set world=("world")
(world)
Set hello=("Hello")
= "hello,world"
(hello)
("")
Set objXMLdoc = Nothing
%>


It should be noted that the XML files generated through XMLDOM are all in UTF-8 format, which makes a good recommendation for the UTF-8 transformation of all our application files.

Summarize

To generate XML data, you can use FSO. If FSO is disabled, you can use XMLDOM, and of course you can also use dynamic documents directly. However, if you master XML operations thoroughly, XMLDOM operations are necessary.
Previous page12Read the full text