UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> XlmFile    
CODE

'---------------------------------------------------------------------------------------------------------------------------------------
' XlmFile
' http://www.utteraccess.com/wiki/index.php/FunctionNameHere
' Code courtesy of UtterAccess Wiki
' Original submission by Diego F.Pereira-Perdomo
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2012-07-10                    Creates XML files.
'                                       strElements: A string that contains the XML Child elements.
'                                       xsdPath:     Optional. The path in which the XSD File is going to be saved.
'                                       xsdName:     The name of the XSD File
'---------------------------------------------------------------------------------------------------------------------------------------
Public Function XlmFile(strElements As String, _
                           xlmPath As String, _
                  Optional xsdPath As String = "") As String

On Error GoTo ErrorHandler

Dim fXml As Long
Dim pXml As String

fXml = FreeFile

' Writes the Parent elements

pXml = "<?xml version='1.0' encoding='UTF-8'?>" & _
      vbCrLf
     
If Nz(xsdPath, "") <> "" Then
   pXml = pXml & "<dataroot " & _
                 "xmlns:od='urn:schemas-microsoft-com:officedata' " & _
                 "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " & _
                 "xsi:noNamespaceSchemaLocation='" & xsdPath & "'>" & _
          vbCrLf
Else
   pXml = pXml & "<dataroot " & _
                 "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " & _
                 "xmlns:od='urn:schemas-microsoft-com:officedata'>" & _
          vbCrLf
End If
   
       ' Writes the Child elements from the variable strElements.
       
       pXml = pXml & strElements
           
   ' Writes the End tags of the Parent elements.

   pXml = pXml & "</dataroot>"

' Creates the XML file

Open xlmPath For Output As #fXml ' Opens the XML file.

   Print #fXml, pXml
   

ExitFunction:

Close #fXml ' Closes the XML file

Exit Function

ErrorHandler:
Select Case Err.Number
   Case 0
   Case Else
       MsgBox Err.Number & ": " & Err.Description
       Resume ExitFunction
End Select

End Function

Creative Commons License
XlmFile by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 1,862 times.  This page was last modified 06:58, 10 July 2012 by dipetete.   Disclaimers