XML is hailed as the life of the future web. This article describes how to use the new XML Document Object Model (DOM) on the server side to parse and apply XML data through an ASP program.
Document Object Model
The ability to parse and apply XML on the server opens up a whole new world for developers. As XML applications become more widely used, it becomes more important to process XML on the server. This article demonstrates ASP application in server-side XML document processing process, the use of XML example is a news document. We'll show you how to write a simple ASP page that displays the date and number of news documents, and how to display the news headlines and corresponding URLs in an ASP page.
The Document Object model, which is the text, is called DOM. The XML Document Object model for IE 5.0 provides complete support for the programming interfaces described in the core specification of the Consortium DOM (Level 1), and it also supports a range of XML-related technologies such as XSL, XSL pattern matching, namespaces, data types, and so on. The DOM is the most basic document model exported by the XML parser, which describes the XML document as a tree structure that can be easily navigated and used.
The DOM Core specification of the consortium defines two sets of DOM programming interfaces. The first set of interfaces is necessary to write applications that process and use XML documents, and the second set of interfaces assists developers in processing XML documents more easily. The second set of interfaces is provided for convenience only and is not required for XML applications.
In ASP applications, it is fairly easy to apply the DOM on the server, but IE 5.0 must be installed on the server because many of the DOM's support components are provided by IE. After installing IE, you can create a DOM object by using code similar to the following in an ASP application:
<% Set objxml = Server.CreateObject ("Microsoft.XMLDOM")%>
II. processing XML on the server (1)
After creating a DOM object on the server, we can either construct the new XML document ourselves or load an existing document. If you are loading an existing document, you can also choose whether to read the XML text string or open the XML document and load its contents. In the example of this article, we assume that there is already a recent news XML document Mostrecentscriptingnews.xml on the server. Before loading an XML document, we should set the Async property of the DOM object to "false", which tells the DOM object that loading the XML document is not asynchronous. This is important because when you read an XML document we will start using it immediately, and if the document is not fully loaded at this point, an error will be raised if you attempt to access it.
<%
Set objxml = Server.CreateObject ("Microsoft.XMLDOM")
Objxml.async = False
Objxml.load (Server.MapPath ("Mostrecentscriptingnews.xml"))
%>
Here is the XML document we loaded Mostrecentscriptingnews.xml:
<?xml version= "1.0" encoding= "gb2312"?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.