开发者

VBScript Converting XML Data to an ADODB RecordSet

开发者 https://www.devze.com 2023-01-21 18:45 出处:网络
I have a situation in which I need to dump XML into an ADODB Recordset in VBScript. My XML is in the form below. What I would like to do in my code is convert the XML into a recordset with AddressObje

I have a situation in which I need to dump XML into an ADODB Recordset in VBScript. My XML is in the form below. What I would like to do in my code is convert the XML into a recordset with AddressObject rows. The code below I tried but keep running into one DomDocument error after another. Can anyone please help me with a solution for this? I tried the code below in Notepad++ but still unable to get the right result.

<?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" />
  开发者_Go百科                      <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


Ado cannot handle an xml recordset. I think you need to use the old XML parser to get the data out. You could throw it into a db and then use ado to manipulate the data once its in a database.

Classic asp makes it very hard to work with Soap web services. I would strongly suggest coding this portion of your application in ASP.net ..

0

精彩评论

暂无评论...
验证码 换一张
取 消