ASP XML Programming Objxml.async = False 1th/2 page _ Application Tips

Source: Internet
Author: User
Tags xml parser xsl
Technically, there are three main ways to read and manage XML text in an ASP environment:
Creates the MSXML object and loads the XML document into the DOM;
Use server-side embedding (Server-side Include,ssi);
Use FileSystemObject to access XML documents just as you would access other text files;
The fourth approach is to create a built-in data island on the client, and then explain the content later.
first, using the DOM
In order to use DOM in ASP code, you need to create an instance of a Microsoft XML parser that is instantiated like any other COM component, Xu to add a few lines of standard code at the beginning of the page. The code creates a parser instance, loads the XML document into the DOM, and sets the root element, which is the document element, as the current node.
' Instatiate the XML Processor
Set objxml = Server.CreateObject ("Microsoft.XMLDOM")
Load the XML Document
Objxml.load (Server.MapPath ("Mydata.xml")
Set the Document Element
Set objrootelement = objxml.documentelement
Before the XML document is loaded, you need to perform step fourth, which is to set the Validateonparse property to True, which ensures that the loaded document is a valid XML document. This avoids all the trouble that comes with the following:
Instatiate the XML Processor
Set objxml = Server.CreateObject ("Microsoft.XMLDOM")
The Processos should validate the document
Objxml.validateonparse = True
Load the XML Document
Objxml.load (Server.MapPath ("Mydata.xml")
Set the Document Element
Set objrootelement = objxml.documentelement
Finally, there is an optional step, which is also present before loading. It requires that the file be loaded synchronously:
Objxml.async = False
This says when loading and verifying a fairly large file takes some time. Another alternative is to ignore this step and allow asynchronous loading, which is the default, and once these initialization steps are completed, the XML document is loaded and prepared for processing. All the important functions of the DOM are configurable.
Of course, just like any COM object, after use, remember that you must destroy it:
Set Objxml = Nothing
second, server-side embedding
Server-side embedding can be used to insert XML document code into an ASP page.
example of using ASP code to process XML
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Dim Sourcefile,source,rootelement,htmlcode
SourceFile = Request.ServerVariables ("Appl_physical_path") & "Xml\contacts.xml"
Set Source = Server.CreateObject ("Microsoft.XMLDOM")
Source.async = False
Source.load sourcefile
Set rootelement = Source.documentelement
Htmlcode = Htmlcode & "<font size=4 face=verdana>"
Htmlcode = htmlcode & Rootelement.childnodes (0). Text
Htmlcode = Htmlcode & "</font><p></p><font size=3 face=verdana><i>"
Htmlcode = htmlcode & Rootelement.childnodes (0). Text
Htmlcode = Htmlcode & "</i></font><p></p><font size=3 face=verdana>"
Htmlcode = htmlcode & Rootelement.childnodes (0). Text
Htmlcode = Htmlcode & "</font><p></p>"
Response.Write (Htmlcode)
Set Source = Nothing
%>
</BODY>
</HTML>
Contacts.xml
<?xml version= "1.0"?>
<CONTACT_INFO>
<CONTACT>
<NAME>JOHN</NAME>
<PHONE>111-1111-111</PHONE>
</CONTACT>
<CONTACT>
<NAME>SMITH</NAME>
<PHONE>222-2222-222</PHONE>
</CONTACT>
<CONTACT>
<NAME>MIKE</NAME>
<PHONE>333-3333-333</PHONE>
</CONTACT>
</CONTACT_INFO>
XML data formatted by XSL
Stylecontact.asp
<HTML>
<BODY>
<%
SourceFile = Server.MapPath ("Contact.xml")
Stylefile = Server.MapPath ("contact.xsl")
Set Source = Server.CreateObject ("Microsoft.XMLDOM")
Source.async = False
Source.load (sourcefile)
Set style = Server.CreateObject ("Microsoft.XMLDOM")
Style.async = False
Style.load (Stylefile)
Response.Write (Source.transformnode (style))
%>
</BODY>
</HTML>
Contact.xml
<?xml version= "1.0"?>
<?xml-stylesheet type= "text/xsl" href= "contact.xsl"?>
<CONTACT_INFO>
<CONTACT>
<name>zhou. Zf</name>
<PHONE>11111111111</PHONE>
</CONTACT>
<CONTACT>
<NAME>LISTEN</NAME>
<PHONE>22222222222</PHONE>
</CONTACT>
<CONTACT>
<NAME>BUBU</NAME>
<PHONE>33333333333</PHONE>
</CONTACT>
</CONTACT_INFO>
Contact.xsl
<?xml version= "1.0"?>
<xsl:template xmlns:xsl= "Http://www.w3.org/TR/WD-xsl" >
<HTML>
<BODY>
<xsl:for-each select= "Contact_info/contact" >
<DIV>
<xsl:value-of select= "NAME"/>
</DIV>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
Current 1/2 page 12 Next read the full text
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.