How to load recordset XML and schema into ADO?

How to load recordset XML and schema into ADO?

Post by Craig Buchana » Thu, 01 Nov 2001 22:55:43



What is the right way to load an ADO recordset with values in XML?  Do I need to include the schema?  If I don't include the schema, will I be able to update the recordset?  Any tricks to getting data into MS' XML recordset format if the data comes from a browser?  I've had difficult getting the MSXMLv4 parser to accept z:row and rs:data when a schema isn't included.

Thanks,

Craig Buchanan
______________________________________________________________________________
Crystal Decisions USENET forums at http://www.cogniza.com/support/forums

 
 
 

How to load recordset XML and schema into ADO?

Post by Amitabh Ghata » Thu, 01 Nov 2001 23:32:36


The following is sample code in c++. There are a few other ways to do
it...this seems to be the most efficient. e.g you could read the recordset
into text by simply doing pStm->ReadText(adReadAll). Although this is less
code, its also less efficient.

//This const is 128KB: recommended value to use as tested by Microsoft
 const int readBytes =  131072;

 _variant_t vnull;
 vnull.vt = VT_ERROR;
 vnull.scode = DISP_E_PARAMNOTFOUND;

 IXMLDOMDocumentPtr pXMLDOMDoc;
 pXMLDOMDoc.CreateInstance(__uuidof(DOMDocument));

  _RecordsetPtr pRstAccess;
  _StreamPtr pStm;

  pRstAccess.CreateInstance("ADODB.Recordset");
  pStm.CreateInstance("ADODB.Stream");

//open the recordset
  pRstAccess->CursorLocation = adUseClient;
  pRstAccess->LockType = adLockBatchOptimistic;
  pRstAccess->Open((LPCTSTR)pDBInfo->strSQL,
(_variant_t)((IDispatch*)DBConn), adOpenStatic, adLockBatchOptimistic,
adCmdText);

  CString strRst;
  if(pRstAccess->State==adStateOpen)
  {
    //save the recordset to a stream
   HRESULT hr = pRstAccess->Save(pStm.GetInterfacePtr(), adPersistXML);
   while(!pStm->EOS)
   {
        //read the recordset into plaintext.
        strRst = strRst + (LPCTSTR)pStm->ReadText(readBytes);
   }
   pRstAccess->Close();

}



Quote:> What is the right way to load an ADO recordset with values in XML?  Do I

need to include the schema?  If I don't include the schema, will I be able
to update the recordset?  Any tricks to getting data into MS' XML recordset
format if the data comes from a browser?  I've had difficult getting the
MSXMLv4 parser to accept z:row and rs:data when a schema isn't included.
Quote:

> Thanks,

> Craig Buchanan

____________________________________________________________________________
__
Quote:> Crystal Decisions USENET forums at http://www.cogniza.com/support/forums


 
 
 

How to load recordset XML and schema into ADO?

Post by Val Mazu » Fri, 02 Nov 2001 02:43:43


Hi Craig,

Go to MSDN and search for "XML Integration Features in ADO
2.5" article. It describes XML format of ADO recordset.

Val

Quote:>-----Original Message-----
>What is the right way to load an ADO recordset with

values in XML?  Do I need to include the schema?  If I
don't include the schema, will I be able to update the
recordset?  Any tricks to getting data into MS' XML
recordset format if the data comes from a browser?  I've
had difficult getting the MSXMLv4 parser to accept z:row
and rs:data when a schema isn't included.
Quote:

>Thanks,

>Craig Buchanan

>__________________________________________________________

____________________
Quote:

>Crystal Decisions USENET forums at

http://www.cogniza.com/support/forums
Quote:>.

 
 
 

1. XML Schema / XML Bulk Load

I am attempting to use the XML Bulk Load component but I am having
troubles with the schema (I believe).  After performing the Bulk Load,
my Companies_Test table has two records but both are NULL.  I do not
have any control over the XML File that I am receiving.  The GVKEY is
the primary key for each company.

Any assistance would be greatly appreciated.

-->XML File
 <?xml version="1.0" ?>
- <procind>
  F
- <procname>
  eval_company
- <timedate>
  20020522-08:59:50
- <group>
  company
- <GVKEY>
  001034
- <rectype>
  I
  <ADD1>Street 1</ADD1>
  <ADDZIP>Zip 1</ADDZIP>
  <CONM>Company Name 1</CONM>
  </rectype>
  </GVKEY>
- <GVKEY>
  001076
- <rectype>
  I
  <ADD1>Street 2</ADD1>
  <ADDZIP>Zip 2</ADDZIP>
  <CONM>Company Name 2</CONM>
  </rectype>
  </GVKEY>
  </group>
  </timedate>
  </procname>
  </procind>

-->Schema
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
  <xsd:element name="GVKEY" sql:relation="Companies_Test" >
   <xsd:complexType>
     <xsd:sequence>
       <xsd:element name="GVKEY" sql:field="GVKEY" type="xsd:string"  />
       <xsd:element name="CONM" sql:field="CONM" type="xsd:string"  />
     </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

2. Ingres II Replication to SQL Sever 7 Help

3. Problems loading XML file into an ADO recordset when app is compiled

4. money data type

5. Load generic XML to ado recordset

6. very large tables

7. Load XML file to a RecordSet then Update Database using ADO

8. vni-2015 Authentication Error

9. ADO Newbie: Saving and loading Recordsets to XML

10. loading an XML file as an ADO recordset (possibly using DOMDocument) in Visual Basic

11. ADO update of recordset loaded from dynamically-generated XML

12. Load ADO Recordset with XML String in VB6

13. Loading Xml Data returned from the query loaded into recordset