When the XML data is combined into the ASP application, the first thing you need to do is to access the contents of the XML file. From a technical manner, in the ASP environment, there are three main methods for reading and managing XML text: create a MSXML object, and load the XML document into the DOM; use server-side incrude, ssi; just like access Like other text files, use FileSystemObject to access the XML document; the fourth method is to create a built-in data island on the client, and explain later. First, use the DOM to use DOM in the ASP code, you need to create an instance of a Microsoft XML analyzer, which is instantiated as any other COM component, and you should add a few line standard code on the start of the page. These codes create an analyzer instance, load an XML document to the DOM, and set the root element (ie, document elements) to the current node. 'Instatiate the XML ProcessorSet objXML = Server.CreateObject ( "Microsoft.XMLDOM")' Load the XML DocumentobjXML.load (Server.MapPath ( "mydata.xml") 'Set the Document ElementSet objRootElement = objXML.documentElement is loaded in the XML document Before, you need to perform the fourth step, that is, set the validateonParse property to TRUE, ensuring that the loaded document is a valid XML document. This avoids the troubles encountered later: 'Instatiate the xml processorset ObjXml = Server.createObject ( "Microsoft.XMLDOM") 'The processos should validate the documentobjXML.validateOnParse = True'Load the XML DocumentobjXML.load (Server.MapPath ( "mydata.xml")' Set the Document ElementSet objRootElement = objXML.documentElement Finally, there An optional step, it also appears before loading. It requires synchronous load file: objxml.async = false This is said to load and verify a considerable file requires some time. Another replacement is ignored this step, allowed Non-synchronous load, this is the default, once these initialization steps are completed, the XML document is loaded, and the preparation of the processed. All important functions of Dom are configurable. Of course, just like any COM object After use, keep in mind that it must be destroyed: set objxml = Nothing 2, the server-side embedding server embedding can be used to insert an XML document code into the ASP page.
Third, use an ASP code to process XML example
head> <% 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 & "" HTMLCode = HTMLCode & rootElement.childNodes (0) .Text htmlcode = htmlcode & " font> " htmlcode = htmlcode & rootElement.childNodes (0) .text htmlcode = HTMLCode & " I> " htmlcode = htmlcode & rootElement.childNodes (0) .text htmlcode = htmlcode & " font> p> "response.write (htmlcode) set source = Nothing%> body> xml version =" 1.0 "?> 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"?> Sub showform%>