2010-10-26 183 views
0

我有一種情況需要將XML轉儲到VBScript中的ADODB Recordset中。我的XML格式如下。我想在我的代碼中執行的操作是將XML轉換爲具有AddressObject行的記錄集。下面的代碼我嘗試過,但一直運行到另一個DomDocument錯誤。任何人都可以請幫我解決這個問題嗎?我在Notepad ++中嘗試了下面的代碼,但仍然無法獲得正確的結果。VBScript將XML數據轉換爲ADODB RecordSet

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Header> 
     <AuthorizationToken xmlns="http://www.avectra.com/2005/"> 
      <Token>8d92d5ba-8b06-4464-9829-86eacac68e6c</Token> 
     </AuthorizationToken> 
    </soap:Header> 
    <soap:Body> 
     <GetQueryResponse xmlns="http://www.avectra.com/2005/"> 
      <GetQueryResult> 
       <AddressObjects xsi:schemaLocation="http://www.avectra.com/2005/ Address.xsd" recordReturn="1"> 
        <AddressObject> 
         <adr_key>2bbcd09f-89c7-4558-93bb-ce23e832ab94</adr_key> 
         <adr_line1>1447 Limerick Lane</adr_line1> 
         <adr_line2 xsi:nil="true" /> 
         <adr_line3 xsi:nil="true" /> 
         <adr_city>Canyon Lake</adr_city> 
         <adr_state>TX</adr_state> 
         <adr_post_code>78133</adr_post_code> 
         <adr_city_state_code>Canyon Lake, TX 78133</adr_city_state_code> 
         <adr_country>UNITED STATES</adr_country> 
         <adr_intl_province xsi:nil="true" /> 
         <adr_county>Comal</adr_county> 
         <adr_bad_address_flag>0</adr_bad_address_flag> 
         <adr_no_validation_flag>0</adr_no_validation_flag> 
         <cst_id>001049008I</cst_id> 
        </AddressObject> 
       </AddressObjects> 
      </GetQueryResult> 
     </GetQueryResponse> 
    </soap:Body> 
</soap:Envelope> 


Public Function XMLToRecSet(Byref objXMLDoc2) 
Dim rsReturn 
Dim node 
Dim attr ,attrs 
Dim ObjXmlDoc 

     Set ObjXmlDoc = CreateObject("MSXML2.DOMDocument.3.0") 
     'Create/open the disconnected recordset 
    ObjXmlDoc = objXMLDoc2 
    Set node = objXMLDoc.selectSingleNode("//AddressObject/") 
    If(Not node Is Nothing) Then 
     Set rsReturn = CreateObject("ADODB.Recordset.6.0") 

     Set attrs = node.getAttributes() 
    for Each attr In attrs 
     rsReturn.Fields.Append attr.nodeName, adVarWChar, 255 
    Next 

    rsReturn.CursorLocation = adUseClient 
    rsReturn.CursorType = adOpenStatic 
    rsReturn.LockType = adLockOptimistic 
    rsReturn.Open 
    Set node = Nothing 
    'Loop/add rows 
    For Each node In objXMLDoc.selectNodes("//AddressObject/") 
     rsReturn.AddNew 
     For Each attr In node.Attributes 
     If(Not rsReturn(attr.nodeName)Is NOTHING) Then 
     rsReturn(attr.nodeName) = 1'attr.nodeValue 
     End if 
     Next 
    Next 

    If rsReturn.RecordCount <> 0 Then rsReturn.MoveFirst 

    'cExit: 
    End If 
    'Dispose DOM document 
    Set objXMLDoc = Nothing 

    Set XMLToRecSet = rsReturn 
    Set rsReturn = Nothing 

End Function 

回答

2

Ado無法處理xml記錄集。我認爲你需要使用舊的XML解析器來獲取數據。你可以把它放入一個數據庫,然後使用ado來處理數據庫中的數據。

經典asp使得使用Soap web服務非常困難。我強烈建議您在ASP.net中編寫您的應用程序的這一部分..