Save the following code as ASP_XML.ASP to run:
<
%
'
By Dicky 2005-03-22 21:52:18 AM QQ: 25941 E-mail: applebbs@gmail.com
Const
ISSQL
=
1
'
Define database types for SQL Server
Call
OpenCONN (CONN)
'
Open database connection
DIM
RS, SQL
Set
RS
=
Server.
CreateObject
(
"
AdoDb.recordset
"
SQL
=
"
Select * from products Order by ProductName
RS.Open SQL, CONN,
1
,
1
'
Query data records in read-only mode
IF
Rs.eof
THEN
Response.write
"
Sorry, no record!
"
'
If there is no record
Else
DIM
Objxmldom, ObjRootnode, ObjNode
Set
Objxmldom
=
Server.
CreateObject
(
"
Msxml2.domdocument
"
)
'
Create an XML document object
Set
Objrootnode
=
ObjxmlDom.createElement
"
xml
"
)
'
Create root node
Objxmldom.documentelement
=
Objrootnode
DO
While
NOT
Rs.eof
'
Circular all records
'
Response.write RS ("ProductName") & "
"
Set
Objrownode
=
ObjxmlDom.createElement
"
Row
"
)
'
Create a parent node
Set
ObjNode
=
ObjxmlDom.createElement
"
ProductName
"
)
'
Create a child node
ObjNode.Text
=
RS (
"
ProductName
"
) Objrownode.Appendchild (ObjNode)
Set
ObjNode
=
ObjxmlDom.createElement
"
Unitprice
"
) ObjNode.Text
=
RS (
"
Unitprice
"
) Objrownode.Appendchild (ObjNode)
Set
ObjNode
=
ObjxmlDom.createElement
"
UnitsInstock
"
) ObjNode.Text
=
RS (
"
UnitsInstock
"
) Objrownode.appendchild (objNode) Objrootnode.Appendchild (objrownode) rs.movenext:
Loop
'
Cycle end
Objxmldom.save
"
D: /MYXMLDoc.xml
"
'
Write XML files You can use variables to let users customize file names on the page.
Response.write
"