Click to See Complete Forum and Search --> : Passing XML Record with XML in VB?


SMR
August 2nd, 2000, 03:47 PM
I want to write a generic component that connects to a database, creates an XML Object (??XML Something??) from an ADO Recordset and returns the XML Object. This is easy to do if just returning an ADO Recordset, ignoring the XML. Someone told me I could create an XML Object of some kind in memory, and return the XML Object(in memory, not using any XML files). Is this true?? If so, what XML object(s) - syntax.
Thanks in advance

dfwade
August 31st, 2000, 02:35 PM
You have two options the first is quick and easy to implement. Performance is something of an issue.
Open a Recordset and use the save method to save out to XML. Open the saved File as a string then delete the file. Then use the string variable.

the other method is to open a recordset and then build an XML string from the msmxl object. You have more control but it is a lot more difficult to implement. Devx.com has some papers on how to do this.

Personally, I would opt for method 1 as it is easy and when ADO+ comes out, It looks like it will support XML much easier.

Last but not least if you are using SQL Server there is an option pack that supports XML as a return natively. Hopefully you have that much control over your environment.

Shahjahan
September 27th, 2000, 06:41 AM
well, i can suggest a generic soution that written below in form of psuedocode, i think u now creating element and XML doc.

1. create connection and recordset
2. execute the query ....
3. create a xmlDOM object...(XMLDOC)

rec.movefirst
dim i as long
do until rec.eof
create record element (oRecElem)
for each fld in rec.fields
create fld element (ofldElem) using fld name
set ofldElem= xmldoc.createElement(fld.name)
olfd.text=fld.value
append field element into recElem
next
append oRecElem into XMLDoc
rec.movenext
loop

Shashidhar
October 30th, 2000, 04:46 AM
Look into ado stream object for saving the xml file into a string variable.
This keeps the xml temporarily for a session without storing it in a file.

Shashidhar

markwilson
May 10th, 2001, 05:07 AM
When Microsoft introduced ADO 2.0, a new method was included on the Recordset object - the Save method.

The Save method accepts two arguments, FileName and PersistFormat. At the time, the only PersistFormat you could use was "adPersistADTG” which was a binary format.

Sub Save([FileName as String],[PersistFormat As PersistFormatEnum = adPersistADTG])

In ADO 2.0, the only member of the Enum PersistFormatEnum was adPersistADTG and you could use it in the following example ways...
http://www.vbxml.com/xml/guides/developers/ado_persist_xml.asp


But this is a MUCH better article
http://www.vbxml.com/xsl/articles/xsl_ado/Default.asp

ADO exports a recordset in an XML format through the .save adPersistXML method. This method persists a recordset to a file or ( from version 2.5 ) to a Stream in an XML format. This feature is very useful for sending data to a client from a web server and can become really interesting if coupled with XSLT. Through this technology we can transform our XML data into HTML, separating the presentation from the data and making a step further towards reusability. This article explores the characteristics of the ADO recordset XML document and shows some sample uses of this technology through XSLT.

For this article ADO 2.5 is used, while the XML parser is MSXML 2.0. This parser has the first and incomplete implementation of XSLT (at that time still called XSL ), but is the default that ships with Internet Explorer 5.0, which is the browser target of this document. The explanations assumes that the reader has basic knowledge of ADO and databases and familiarity with XSL(T), in particular with the context() operator. The context() operator provides a method for evaluating the position of a node in the context of a query. It's similar to the XSLT position() function found in the XSLT specification