Since XML (Scalable Markup Language: Extensible Markup Language) is unrelated, it is gradually become the main media of data transmission. XML is a self-description language that has already included metadata, which is information about the data itself. For example: "Menciic E-chapter 1757281793923NET_LOVER1807581793923" This group of data, it is difficult to see what it means from the literal, and it does not know how many data segments are composed. However, if you use XML to do the following description, we can clearly look clear The meaning representative of each data segment:
Persons>
Persons>
Persdata>
From the above XML, we can not only see what the representatives of each data are meaningful, but also you can know the split position of the data. In our usual applications, the results we get may be an array, a collection, or a collection of records, how do we convert them into data from the XML format? From the data form, XML is a simple string text format. The string is very simple, fast and easy, and the array is sometimes very slow when passing the reference, and it is very troublesome. And the collection and recording sets are objects, which will result in a decline in computer performance during processing, and these objects are associated with a particular platform, which requires the platform to have built-in processing mechanisms to process objects. Operation. XML is already the standard of W3C. It is a platform-independent. The only requirement of our computer is to handle simple XML strings, the XML parser, which can parse the XML string, which can be exploded by an interface. It is a separate data segment so that we can access. The XML parser is very small, the performance is also very good, can be found on each platform. Once we receive XML data and analyze it to the above example, we can convert them into different expressions through XSLT (Exstensible Stylesheet Language Transformations). Data transfer by using XML data format will make our application code easier and have good scalability.
Below, let's take a look at how to convert our data. Our example is written in Microsoft Windows 2000, IIS5, MSXML3, and ADO2.6, which uses the Northwind sample database that comes with Microsoft SQL Server 7.0. The reason why SQL Server7 does not use SQL Server2000 that supports XML, is a principle of versatility, our purpose is to handle different types of data sources, not just support XML output like SQL Server2000. Data source. Using ADO because it is diverse, you can handle different types of data sources; use XML because it can transmit and resolve. However, the processing method of this example is also suitable in any environment with a MicrSoft XML parser, ADO2.5 or above, of Windows, IIS, SQL Server. For the sake of simplicity, we only choose a unit price of less than 20 mines, the stock is greater than or equal to 20, the product name is less than or equal to 6 characters:
<%
DIM ObjRecordset
Set objRecordset = server.createObject ("adoDb.recordset")
ObjRecordset.open_
"SELECT ProductName, Unitprice, UnitsInstock" _
& "From products" _
& "Where unitprice <= 20" _
& "And UnitsInstock> = 20" _
& "And leductname" <= 6 "_
& "Order by ProductName", _
"Provider = SQLOLEDB;" _ _
& "Data Source = SomeSqlserver;" _
& "Initial Catalog = Northwind;" _
& "User ID = myusername;" _ _
& "Password = mypassword;"
%>
Now, we use three ways to convert our record set into XML format.
First, we can traverse the entire recordset, using XML DOM (Document Object Model), establish XML node tree:
<% Dim objXMLDOM, objRootNode, objNode Set objXMLDOM = Server.CreateObject ( "MSXML2.DOMDocument") Set objRootNode = objXMLDOM.createElement ( "xml") objXMLDOM.documentElement = objRootNode Do While NOT objRecordset.EOF Set objRowNode = objXMLDOM.createElement ( "row") Set objNode = objXMLDOM.createElement ( "ProductName") objNode.text = objRecordset.Fields.Item ( "ProductName"). Value objRowNode.appendChild (objNode) Set objNode = objXMLDOM.createElement ( "UnitPrice") objNode. text = objRecordset.Fields.Item ( "UnitPrice"). Value objRowNode.appendChild (objNode) Set objNode = objXMLDOM.createElement ( "UnitsInStock") objNode.text = objRecordset.Fields.Item ( "UnitsInStock"). Value objRowNode.appendChild (ObjNode) ObjRootnode.Appendchild (Objrownode) ObjRecordSet.Movenext loop set objNode = Nothing set objRownode = nothing set objRecordset = Nothing%>
Now, we get an XML DOM object. This approach is not ideal for the record set very much, as the ADO record set object and the XML DOM object are saved in the system memory. The second approach, traverses the record set, directly generate XML string itself: <% DIM strXml strXml = "
<% Dim strXML strXML = "
s: ElementType>
s: schema>
rs: data>
XML> ADO automatically generated XML contains SCHEMA information, which describes what nodes and properties allowed in this XML and what data types are used, and the data nodes also add namespaces. SCHEMA information is very useful in places requiring data verification or more complex processing, but in most cases, we use thin clients, we don't need SCHEMA information. We can use XSLT to separate the information we want and remove excess information. Therefore, we write the following "Dataclener.xsl":
XML Version = "1.0"?>