one must find out what is needed in the end
Through ASP or other dynamic programming languages, we ultimately need XML-formatted data, which has nothing to do with the file carrier of the XML data, it can be a real XML file, such as: Http://www.dw8.cn/common/dw8.xml. It can also be an ASP document, such as: http://www.cnbruce.com/blog/rss2.asp
They are the embodiment of XML data, in order to realize the dynamic of XML data, so need to use a dynamic programming language, such as ASP to implement it.
Ii. How to generate a dynamic XML document
If the XML file is generated, the dynamic document is in ASP format, so you must use the FSO for the generation of XML files, such as:
<%
Xmlfile=server.mappath ("Test1.xml")
Set fso = CreateObject ("Scripting.FileSystemObject")
Set MyFile = fso. CreateTextFile (Xmlfile,true)
MyFile.WriteLine ("")
MyFile.WriteLine ("< World >")
MyFile.WriteLine ("< hello >hello,world")
MyFile.WriteLine ("")
Myfile.close
%>
View XML File Contents
For an operation on the FSO see
http://www.cnbruce.com/blog/showlog.aspcat_id=26&log_id=440
In the case of generating dynamic XML data files, it is possible to control the name and value of the XML node by means of the program in the dynamic document by the MyFile.WriteLine related content.
Iii. How to generate XML data using dynamic documents
So if you're not generating an XML file and you're outputting XML data directly on a dynamic document, you need to declare the type of file (i.e. Response.ContentType)
<%response.contenttype = "Text/xml"%>
For example, directly browse the following dynamic ASP document, in the browser next to display as XML data tree
<%
With Response
. ContentType = "Text/xml"
. Write ("")
. Write ("< World >")
. Write ("< hello >hello,world")
. Write ("")
End With
%>
The advantage of the generated XML file is that documents that process the XML data can be static documents, such as HTML files that parse XML through JavaScript, XMLDOM, and also ease data retention, while dynamic XML data on dynamic documents is not. However, in today's dynamic documents everywhere in the era, it seems that this advantage for some applications is not very influential, even, dynamic document XML data flow instead more advantages: more timely, more dynamic.
Iv. generate XML data that's it, all right?
Whether by generating a specific XML file or a dynamic XML data stream, you can simply export the relevant XML nodes and values in the format of XML, so that XML seems simple. But this does not really touch the XML operation. In our view, these XML is nothing more than a pair of tags and related characters composed of data records, there is no vitality to speak. In reality, however, manipulating XML through XMLDOM shows the absolute advantages of XML (this is not an obvious advantage when generating XML, but it experiences infinity when adding and deleting XML nodes).
Using XMLDOM to create an XML document, you can use the Save method to generate an XML document, create an XML element using the CreateElement method, CreateNode Create a node, and, in fact, choose one of these for any label in the XML. However, you typically use createelement to create a top-level (root) element, and you use CreateNode to create child nodes (elements), and of course createelement and CreateNode are different ways to use them.
<%
Set objXMLDoc = CreateObject ("Microsoft.XMLDOM")
Set world=objxmldoc.createelement ("World")
Objxmldoc.appendchild (World)
Set Hello=objxmldoc.createnode ("element", "Hello", "")
Hello. Text = "Hello,world"
ObjXMLdoc.documentElement.appendChild (Hello)
Objxmldoc.save Server.MapPath ("Test2.xml")
Set objXMLDoc = Nothing
%>
CreateObject ("Microsoft.XMLDOM") declares the use of XMLDOM objects
When an element or node is built (createelement, CreateNode), it is not added to the file tree, and to add nodes to the file tree, you need to insert, such as appendchild.
Xmldocument.createnode (type, name, NamespaceURI) represents a new node that creates 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 prefix of the namespace is optional. NamespaceURI is a string that defines the namespace URI. If the prefix is contained in the name parameter, the node is established in the NamespaceURI text with the specified prefix. If you do not include a prefix, the specified namespace is considered a preset namespace.
Objxmldoc.createnode ("element", "Hello", "") Equals objxmldoc.createelement ("Hello") 4,objxmldoc.documentelement.appendchild (hello) is actually the creation of nodes under the root element of the XML document, in this case the equivalent of World.appendchild (hello), world as the node name in this example, and so on.
So you can write this:
<%
Set objXMLDoc = CreateObject ("Microsoft.XMLDOM")
Set world=objxmldoc.createelement ("World")
Objxmldoc.appendchild (World)
Set hello=objxmldoc.createelement ("Hello")
Hello. Text = "Hello,world"
World.appendchild (Hello)
Objxmldoc.save Server.MapPath ("Test2.xml")
Set objXMLDoc = Nothing
%>
It is important to note that the XML files generated through XMLDOM are UTF-8 formatted, which is a good introduction to the UTF-8 of all our application files.
Summary
Generate XML data, you can use the FSO, such as the FSO is disabled, you can use XMLDOM, of course, you can also directly use dynamic documents. However, if you master the operation of XML, XMLDOM operations are necessary.