title: VBScript Converting XML Data to an ADODB RecordSet
body: <p>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.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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"&gt;
      &lt;soap:Header&gt;
          &lt;AuthorizationToken xmlns="http://www.avectra.com/2005/"&gt;
              &lt;Token&gt;8d92d5ba-8b06-4464-9829-86eacac68e6c&lt;/Token&gt;
          &lt;/AuthorizationToken&gt;
      &lt;/soap:Header&gt;
      &lt;soap:Body&gt;
          &lt;GetQueryResponse xmlns="http://www.avectra.com/2005/"&gt;
              &lt;GetQueryResult&gt;
                  &lt;AddressObjects xsi:schemaLocation="http://www.avectra.com/2005/ Address.xsd" recordReturn="1"&gt;
                      &lt;AddressObject&gt;
                          &lt;adr_key&gt;2bbcd09f-89c7-4558-93bb-ce23e832ab94&lt;/adr_key&gt;
                          &lt;adr_line1&gt;1447 Limerick Lane&lt;/adr_line1&gt;
                          &lt;adr_line2 xsi:nil="true" /&gt;
                          &lt;adr_line3 xsi:nil="true" /&gt;
                          &lt;adr_city&gt;Canyon Lake&lt;/adr_city&gt;
                          &lt;adr_state&gt;TX&lt;/adr_state&gt;
                          &lt;adr_post_code&gt;78133&lt;/adr_post_code&gt;
                          &lt;adr_city_state_code&gt;Canyon Lake, TX  78133&lt;/adr_city_state_code&gt;
                          &lt;adr_country&gt;UNITED STATES&lt;/adr_country&gt;
                          &lt;adr_intl_province xsi:nil="true" /&gt;
                          &lt;adr_county&gt;Comal&lt;/adr_county&gt;
                          &lt;adr_bad_address_flag&gt;0&lt;/adr_bad_address_flag&gt;
                          &lt;adr_no_validation_flag&gt;0&lt;/adr_no_validation_flag&gt;
                          &lt;cst_id&gt;001049008I&lt;/cst_id&gt;
                      &lt;/AddressObject&gt;
                  &lt;/AddressObjects&gt;
              &lt;/GetQueryResult&gt;
          &lt;/GetQueryResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  
  
  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 &lt;&gt; 0 Then rsReturn.MoveFirst
  
     'cExit:
     End If 
     'Dispose DOM document
     Set objXMLDoc = Nothing
  
     Set XMLToRecSet = rsReturn
     Set rsReturn = Nothing
  
  End Function
  </code></pre>