title: Help passing XML String to RecordSet
body: <p>What I would like to do is dump an XML String into RecordSet. The problem I am having is that the code seems to work fine if I saved the XML String first to a file and then read from the file which I think is redundant. However, when I want to read from string, I get the error </p>
  
  <p><strong>RecordSet cannot be created. Source XML is incomplete or invalid. 80004005</strong></p>
  
  <p>My XML String is in the form </p>
  
  <pre><code>&lt;portfolio&gt;
     &lt;stock&gt;
        &lt;shares&gt;100&lt;/shares&gt;
        &lt;symbol&gt;MSFT&lt;/symbol&gt;
        &lt;price&gt;$70.00&lt;/price&gt;
        &lt;info&gt;
           &lt;companyname&gt;Microsoft Corporation&lt;/companyname&gt;
           &lt;website&gt;http://www.microsoft.com&lt;/website&gt;
        &lt;/info&gt;
     &lt;/stock&gt;
     &lt;stock&gt;
        &lt;shares&gt;100&lt;/shares&gt;
        &lt;symbol&gt;AAPL&lt;/symbol&gt;
        &lt;price&gt;$107.00&lt;/price&gt;
        &lt;info&gt;
           &lt;companyname&gt;Apple Computer, Inc.&lt;/companyname&gt;
           &lt;website&gt;http://www.apple.com&lt;/website&gt;
        &lt;/info&gt;
     &lt;/stock&gt;
     &lt;stock&gt;
        &lt;shares&gt;100&lt;/shares&gt;
        &lt;symbol&gt;DELL&lt;/symbol&gt;
        &lt;price&gt;$50.00&lt;/price&gt;
        &lt;info&gt;
           &lt;companyname&gt;Dell Corporation&lt;/companyname&gt;
           &lt;website&gt;http://www.dell.com&lt;/website&gt;
        &lt;/info&gt;
      &lt;/stock&gt;
      &lt;stock&gt;
         &lt;shares&gt;100&lt;/shares&gt;
         &lt;symbol&gt;INTC&lt;/symbol&gt;
         &lt;price&gt;$115.00&lt;/price&gt;
         &lt;info&gt;
            &lt;companyname&gt;Intel Corporation&lt;/companyname&gt;
            &lt;website&gt;http://www.intel.com&lt;/website&gt;
         &lt;/info&gt;
     &lt;/stock&gt;
  &lt;/portfolio&gt;
  </code></pre>
  
  <p>And the code I am using to convert the XML String(That I am having the problem with) is </p>
  
  <pre><code>Public Function RecordsetFromXMLString(sXML As String) As Recordset
  
      Dim oStream As ADODB.Stream
      Set oStream = New ADODB.Stream
  
      oStream.Open
      oStream.WriteText sXML   'Give the XML string to the ADO Stream
  
      oStream.Position = 0    'Set the stream position to the start
  
      Dim oRecordset As ADODB.Recordset
      Set oRecordset = New ADODB.Recordset
  
      oRecordset.Open oStream    'Open a recordset from the stream
  
      oStream.Close
      Set oStream = Nothing
  
      Set RecordsetFromXMLString = oRecordset  'Return the recordset
  
      Set oRecordset = Nothing
  
  End Function
  </code></pre>
  
  <p>Please, your help will be greatly appreciated. </p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms810621" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms810621</a></p>
  
  <p><a href="http://support.microsoft.com/kb/263247" rel="nofollow">http://support.microsoft.com/kb/263247</a></p>
  
  <p>I already tried using this below </p>
  
  <pre><code>Public Function RecordsetFromXMLDocument(XMLDOMDocument) 
      Dim oRecordset 
      Set oRecordset = CreateObject("ADODB.Recordset.6.0")
      oRecordset.Open XMLDOMDocument 'pass the DOM Document instance as the Source argument
  
      Set RecordsetFromXMLDocument = oRecordset  'return the recordset
  
      Set oRecordset = Nothing
  End Function
  </code></pre>
  
  <p>But still ran into the same issue.</p>
  
  <hr>
  
  <p>Code I used to Format my DomDocumentData into the ADO XML Persistent Format I required for this </p>
  
  <pre><code>'*******************************************************************************************
  ' SCHEMA GENERATOR
  '*******************************************************************************************
  'parentnodepath -- XPath to the Main Node/Table/RowCollection
  'parentnodepath -- Name of the Main Node/Table/RowCollection
  Function CreateSchemafromNode(XMLDocument,parentnodepath, parentnodeName)
          Dim schema, stemp, MyArray,nodename, childnodelist,counter, n, x, tempnode
          schema = TextWriterSchemaNameSpaceHeader()
          schema=schema &amp; TextWriterSchemaHeader(parentnodeName)
          'LOOP HERE 
            counter = 0
  
              For Each stemp In XMLDocument.SelectSingleNode(parentnodePath).ChildNodes(0).ChildNodes
                      counter = counter + 1
                      schema = schema &amp; TextWriterSchemaRowAttributeElement(stemp.NodeName, counter, "")
              Next
          'END LOOOP HERE
              schema=schema &amp; TextWriterSchemaSchemaEnd
              schema =schema &amp;  TextWriterSchemaRowHeader
             'BEGIN FIRST LOOP HERE -- FOR EACH TOP NODE --ROW
                  For Each n In XMLDocument.SelectSingleNode(parentnodePath).ChildNodes
                          schema =schema &amp; TextWriterSchemaAddRowBegin()
                      'BEGIN SECOND LOOP HERE -- FOR EACH CHILD OF TOP NODE -- NODE VALUE IN CURRENT ROW -- FOR EACH CHILDNODELIST NAME
                      For Each x In n.ChildNodes
                              schema = schema &amp; TextWriterSchemaAddRowFieldNameValue(x.NodeName, x.text) 
                      'END SECOND LOOP HERE 
                      Next
                      schema =schema &amp; TextWriterSchemaAddRowEnd()
             Next 
          'END FIRST LOOP HERE 
          schema =schema &amp; TextWriterSchemaRowEnd()
          schema =schema &amp;TextWriterSchemaNameSpaceEnd()
  
          CreateSchemafromNode=schema
  End Function 
  
  
  Function TextWriterSchemaNameSpaceHeader()
    Dim schemaString 
  
      schemaString= "&lt;xml xmlns:s='"
      schemaString= schemaString &amp; "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' " &amp; vbCrLf &amp; vbTab
      schemaString= schemaString &amp; ("xmlns:dt='")
      schemaString= schemaString &amp; "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' " &amp; vbCrLf &amp; vbTab
    ' schemaString= schemaString &amp; ("xmlns:dt='")
    ' schemaString= schemaString &amp; "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' " &amp; vbCrLf &amp; vbTab
      schemaString= schemaString &amp; "xmlns:rs='urn:schemas-microsoft-com:rowset' "  &amp; vbCrLf &amp; vbTab
      schemaString=schemaString &amp; " xmlns:z='#RowsetSchema'&gt; " &amp; vbCrLf 
      TextWriterSchemaNameSpaceHeader = schemaString 
  End Function
  
  
  Function TextWriterSchemaHeader(recordname)
       Dim schemaString 
              schemaString= "&lt;s:Schema id='RowsetSchema'&gt;"&amp; vbCrLf &amp; vbTab
              schemaString= schemaString &amp;"&lt;s:ElementType name='" &amp; recordname &amp; "' content='eltOnly'&gt;" &amp; vbCrLf 
              TextWriterSchemaHeader = schemaString 
  End Function
  
  Function TextWriterSchemaRowAttributeElement(rowname, rowordernumber, rowtype)
      Dim schemaString 
          schemaString=vbTab &amp; vbTab &amp; "&lt;s:AttributeType  name='" &amp; rowname &amp; "'  rs:number='" &amp; rowordernumber &amp; "'  /&gt;" &amp; vbCrLf 
          TextWriterSchemaRowAttributeElement = schemaString
  End Function
  
  Function TextWriterSchemaSchemaEnd()
        Dim schemaString 
          schemaString=vbTab &amp; vbTab &amp; "&lt;s:extends type='rs:rowbase'/&gt;" &amp; vbCrLf 
          schemaString= schemaString &amp;vbTab &amp;  "&lt;/s:ElementType&gt;" &amp; vbCrLf 
          schemaString= schemaString &amp; "&lt;/s:Schema&gt;"  &amp; vbCrLf 
          TextWriterSchemaSchemaEnd =schemaString
  End Function
  
  Function TextWriterSchemaRowHeader()
          Dim schemaString 
              schemaString= vbTab &amp; "&lt;rs:data&gt;" &amp; vbCrLf 
              TextWriterSchemaRowHeader = schemaString
  End function
  
  Function TextWriterSchemaAddRowBegin()
        Dim schemaString 
          schemaString=vbTab &amp; "&lt;z:row "
          TextWriterSchemaAddRowBegin=schemaString
  End function
  
  Function TextWriterSchemaAddRowFieldNameValue(FieldName, FieldValue)
      Dim schemaString 
              schemaString= FieldName &amp; "='" &amp; FieldValue &amp; "' "
              TextWriterSchemaAddRowFieldNameValue=schemaString
  End function
  
  Function TextWriterSchemaAddRowEnd()
          Dim schemaString
             schemaString="/&gt;"  &amp; vbCrLf 
             TextWriterSchemaAddRowEnd=schemaString
  End function
  
  
  Function TextWriterSchemaRowEnd()
           Dim schemaString
                schemaString=vbTab &amp; "&lt;/rs:data&gt;" &amp; vbCrLf 
                 TextWriterSchemaRowEnd=schemaString
  End function
  
  Function TextWriterSchemaNameSpaceEnd()
           Dim schemaString
                 schemaString="&lt;/xml&gt;"  &amp; vbCrLf 
                 TextWriterSchemaNameSpaceEnd=schemaString
  End Function
  </code></pre>