ASP و XML

MxSite

Member
سلام

چه جوري ميشه از محتويات آخرين ركورد در ديتابيس access يه فايل xml ساخت.

حياتي حياتي حياتي :wink:
 

hoom

Active Member
سلام

براي اينكار بايد محتويات ديتابيس خودتون رو با ASP بخونين بعدش با اين تابع هر ركوردي رو كه بخوايين به XML تبديل كننين :

کد:
Function ConvertRStoXML(objRS, strTopLevelNodeName, strRowNodeName)
 
 'Declare local variables.
 Dim objDom
 Dim objRoot
 Dim objField
 Dim objFieldValue
 Dim objcolName
 Dim objattTabOrder
 Dim objPI
 Dim x
 Dim objRSField
 Dim objRow

 'Instantiate the Microsoft XMLDOM.
 Set objDom = server.CreateObject("Microsoft.XMLDOM")
 objDom.preserveWhiteSpace = True

'Create your root element and append it to the XML document.
 Set objRoot = objDom.createElement(strTopLevelNodeName)
 objDom.appendChild objRoot

'Iterate through each row in the Recordset
 Do While Not objRS.EOF

   'Create a row-level node with the name specified by strRowNodeName
   Set objRow = objDom.CreateElement(strRowNodeName)

   'Iterate through each field in the Recordset row
   For Each objRSField in objRS.Fields

     '*** Create an element, "field". ***
     Set objField = objDom.createElement("field")

       '*** Append the name attribute to the field node ***
       Set objcolName = objDom.createAttribute("name")
       objcolName.Text = objRSField.Name
       objField.SetAttributeNode(objColName)
       '***************************************************

       '*** Create a new node, "value". ***
       Set objFieldValue = objDom.createElement("value")

       'Set the value of the value node equal to the value of the
       'current field object
       objFieldValue.Text = objRSField.Value
       '************************************

       '*** Append the value node as a child of the field node. ***
       objField.appendChild objFieldValue
       '***********************************************************

     '*** Append the field node as a child of the row-level node. ***
     objRow.appendChild objField
     '***************************************************************
   Next 

   '*** Append the row-level node to the root node ***
   objRoot.appendChild objRow
   '**************************************************

   objRS.MoveNext    'Move to the next row in the Recordset
 Loop

 '*** Add the <?xml version="1.0" ?> tag ***
 Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
 
 'Append the processing instruction to the XML document.
 objDom.insertBefore objPI, objDom.childNodes(0)
 '************************************************

 'Return the XML contents as a string
 ConvertRStoXML = objDom.xml


 'Clean up...
 Set objDom = Nothing
 Set objRoot = Nothing
 Set objField = Nothing
 Set objFieldValue = Nothing
 Set objcolName = Nothing
 Set objattTabOrder = Nothing
 Set objPI = Nothing
End Function

مثلا

کد:
<%
set myConnection = CreateObject("ADODB.Connection")
myConnection.Open "DSN=myDSN;UID=aUser;PWD=aPass"
SQLQuery = "Select * From PTCOMMPREFS Where (COMMUNITYID=202) ORDER BY PAGENUMBER"
set RS =  myConnection.Execute(SQLQuery)

Response.Write ConvertRStoXML(RS, "MyData", "MyRecord")

set myConnection = Nothing
set RS = Nothing
%>

ارادتمند
 

جدیدترین ارسال ها

بالا