J
J Streger
I am looking to find a way to insert the data from an XML file without having
to loop.
Just seeing if it's possible. The code I have is going to read an XML file
that has the same headers as a worksheet in Excel. I use the code below to
pull the XML file into a DOMDocument, then into a ADO Recordset object. When
I generate an XML file, I can just query the worksheet and get a recordset,
no looping needed. Why can't I do it backwards. I want to do an insert SQL
statement or combine 2 recordsets or something else. as the data can get
really long. Thanks for any help!
'***********************************************************
'*Name: ImportXMLFileToXMLObject
'*Description: This method will take the passed in sPath as load the
'* file into a DOMDocument object
'*Input Params: sPath - String - Path to the XML file to load
'*Returns: DOMDocument - XML Document loaded with data from the passed in
XML file Path
'* returns nothing if Load fails
'*Restrictions: Requires Microsoft XML, v6.0
'* Doesn't verify sPath is a valid path to an XML document
'*Written by Jared Streger, 1/29/2010
'***********************************************************
Function ImportXMLFileToXMLObject(sPath As String) As DOMDocument
Dim myXML As New DOMDocument
'Do nothing until loading is complete
myXML.async = False
'Load XML
If myXML.Load(sPath) Then
'Return Object
Set ImportXMLFileToXMLObject = myXML
End If
End Function 'ImportXMLFileToXMLObject
'***********************************************************
'*Name: ImportXMLFileToRecordset
'*Description: This method will take the passed in sPath as load the
'* file into an Recordset
'*Input Params: sPath - String - Path to the XML file to load
'*Returns: Recordset - ADO recordset loaded with data from the passed in XML
file Path
'* Returns nothing if Load failed
'*Restrictions: Requires Microsoft XML, v6.0
'* Doesn't verify sPath is a valid path to an XML document
'*Written by Jared Streger, 1/29/2010
'***********************************************************
Function ImportXMLFileToRecordset(sPath As String) As Recordset
Dim myXML As DOMDocument
Dim rcdSet As New Recordset
'Load file into a DOM Document
Set myXML = ImportXMLFileToXMLObject(sPath)
'If load didn't fail
If Not myXML Is Nothing Then
'Load recordset with XML
rcdSet.Open myXML
'Return Recordset
Set ImportXMLFileToRecordset = rcdSet
End If
'Clean up
Set myXML = Nothing
End Function 'ImportXMLFileToRecordset
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003
User of MS Office 2003
to loop.
Just seeing if it's possible. The code I have is going to read an XML file
that has the same headers as a worksheet in Excel. I use the code below to
pull the XML file into a DOMDocument, then into a ADO Recordset object. When
I generate an XML file, I can just query the worksheet and get a recordset,
no looping needed. Why can't I do it backwards. I want to do an insert SQL
statement or combine 2 recordsets or something else. as the data can get
really long. Thanks for any help!
'***********************************************************
'*Name: ImportXMLFileToXMLObject
'*Description: This method will take the passed in sPath as load the
'* file into a DOMDocument object
'*Input Params: sPath - String - Path to the XML file to load
'*Returns: DOMDocument - XML Document loaded with data from the passed in
XML file Path
'* returns nothing if Load fails
'*Restrictions: Requires Microsoft XML, v6.0
'* Doesn't verify sPath is a valid path to an XML document
'*Written by Jared Streger, 1/29/2010
'***********************************************************
Function ImportXMLFileToXMLObject(sPath As String) As DOMDocument
Dim myXML As New DOMDocument
'Do nothing until loading is complete
myXML.async = False
'Load XML
If myXML.Load(sPath) Then
'Return Object
Set ImportXMLFileToXMLObject = myXML
End If
End Function 'ImportXMLFileToXMLObject
'***********************************************************
'*Name: ImportXMLFileToRecordset
'*Description: This method will take the passed in sPath as load the
'* file into an Recordset
'*Input Params: sPath - String - Path to the XML file to load
'*Returns: Recordset - ADO recordset loaded with data from the passed in XML
file Path
'* Returns nothing if Load failed
'*Restrictions: Requires Microsoft XML, v6.0
'* Doesn't verify sPath is a valid path to an XML document
'*Written by Jared Streger, 1/29/2010
'***********************************************************
Function ImportXMLFileToRecordset(sPath As String) As Recordset
Dim myXML As DOMDocument
Dim rcdSet As New Recordset
'Load file into a DOM Document
Set myXML = ImportXMLFileToXMLObject(sPath)
'If load didn't fail
If Not myXML Is Nothing Then
'Load recordset with XML
rcdSet.Open myXML
'Return Recordset
Set ImportXMLFileToRecordset = rcdSet
End If
'Clean up
Set myXML = Nothing
End Function 'ImportXMLFileToRecordset
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003
User of MS Office 2003