Kem
03-21-2000, 04:52 AM
Isn't it possible to create XML content from an ADO recordset?
|
Click to See Complete Forum and Search --> : Writing XML from VB Kem 03-21-2000, 04:52 AM Isn't it possible to create XML content from an ADO recordset? Phil Weber 03-21-2000, 06:17 AM > Isn't it possible to create XML content from an ADO recordset? Kem: Yes. The simplest way is to use the .Save method of the Recordset object: rs.Save "d:\path\file.xml", adPersistXML It doesn't create the nicest XML, however, so if you want the file to be easily readable by humans, you may prefer to use the XML DOM (Document Object Model) to manually create an XML file from the recordset data. --- Phil Weber Greg Longtin 03-22-2000, 12:56 AM Kem, What Phil said, but somewhere I recently saw a generic xsl stylesheet that transformed an ado/xml file into more normal xml. Maybe on the devx site somewhere? Sound familiar to anyone? Greg Kem <kem@online.ie> wrote in message news:38d7385d@news.devx.com... > > Isn't it possible to create XML content from an ADO recordset? sean lacey 03-22-2000, 04:32 AM A 10 min solution from Kurt Cagle. http://www.inquiry.com/techtips/xml_pro/10min/10min0100/10min0100.asp I have also enhanced( see below )to support a shaped recordset with one child level. when I get a chance I will enhance it fully to use recursion to support any number of levels. I also corrected some features in the original. Sean Function convertToElementTree(xDom As Variant) As Variant Dim lDom As MSXML.DOMDocument Dim x2DOM As New MSXML.DOMDocument Dim dataNodeList As IXMLDOMNodeList Dim dataNode As IXMLDOMNode, rowNode As IXMLDOMNode, newNode As IXMLDOMNode, newRoot As IXMLDOMNode, newNode2 As IXMLDOMNode, newNode3 As IXMLDOMNode Dim childNode As IXMLDOMNode, newChildNode As IXMLDOMNode Set lDom = xDom Set dataNodeList = lDom.getElementsByTagName("rs:data") Set dataNode = dataNodeList.Item(0) ' Create a new Node under new DOM. Set newRoot = x2DOM.createNode(NODE_ELEMENT, "recordset", "") ' Append root node. Set newRoot = x2DOM.appendChild(newRoot) Dim i As Integer, j As Integer, k As Integer i = 0 k = 1 ' Loop through all z:row nodes. While i < dataNode.childNodes.length ' MsgBox x2DOM.xml ' Get to the z:row node. Set rowNode = dataNode.childNodes.Item(i) Set newNode = x2DOM.createNode(NODE_ELEMENT, "row", "") ' Append row node under new root. Set newNode = newRoot.appendChild(newNode) j = 0 ' Loop through all attributes of z:row. While j < rowNode.Attributes.length ' Create new element for column name. Set newNode2 = x2DOM.createNode(NODE_ELEMENT, rowNode.Attributes.Item(j).baseName, "") ' Assign column value to new node value. newNode2.Text = rowNode.Attributes.Item(j).Text ' Append new column node under new node. Set newNode2 = newNode.appendChild(newNode2) j = j + 1 Wend k = 0 ' MsgBox x2DOM.xml While k < rowNode.childNodes.length Set childNode = rowNode.childNodes.Item(k) Set newChildNode = x2DOM.createNode(NODE_ELEMENT, "child", "") ' Append row node under new root. Set newChildNode = newNode.appendChild(newChildNode) j = 0 ' Loop through all attributes of z:row. While j < childNode.Attributes.length ' Create new element for column name. Set newNode3 = x2DOM.createNode(NODE_ELEMENT, childNode.Attributes.Item(j).baseName, "") ' Assign column value to new node value. newNode3.Text = childNode.Attributes.Item(j).Text ' Append new column node under new node. Set newNode3 = newChildNode.appendChild(newNode3) j = j + 1 Wend k = k + 1 Wend i = i + 1 Wend Set convertToElementTree = x2DOM End Function "Greg Longtin" <longtin@att.net> wrote: >Kem, > >What Phil said, but somewhere I recently saw a generic xsl stylesheet >that transformed an ado/xml file into more normal xml. Maybe on the >devx site somewhere? > >Sound familiar to anyone? > >Greg > >Kem <kem@online.ie> wrote in message news:38d7385d@news.devx.com... >> >> Isn't it possible to create XML content from an ADO recordset? > devx.com
Copyright WebMediaBrands Inc. All Rights Reserved |