Link to home
Start Free TrialLog in
Avatar of chitramahadik
chitramahadik

asked on

Create file in xml format using visual basic 6.0

Hi,
I want to create a file which would be in xml format using file I/O which will loop into the database and display in xml format.As I am not aware of how to create xml file in visual basic.I have created normal text files in VB,Is that the same way for creating xml files.....
Avatar of JonothanTompson
JonothanTompson
Flag of Australia image

Yeah it is the same as making a text file, just as long as your using the correct method
Like below
Open App.Path & "\Test.xml" For Output As #1
    Print #1, Whole  *** whole being the formated xml
Close #1
Avatar of chitramahadik
chitramahadik

ASKER

Can u give me any example for the same ,so I can understand the same well
yes it's just the same.... just give them an xml extension
I am getting the following error
A string literal was expected, but no opening quote character was found. Error processing resource 'file:///C:/invoice.xml'. Line 1, Position 15

<?xml version=3.0?>
--------------^

For ur reference I am pasting my code down

Private Sub cmdCreateXML_Click()
Dim vStrSql As String
Dim vStrfilename As String
Dim vIntFreeHandle As Integer
Dim vRsInvoice As New ADODB.Recordset
Dim oField As ADODB.Field

On Error GoTo ErrorHandler

CommonDialog1.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
CommonDialog1.Filter = "XML Files (*.xml)|*.xml"

CommonDialog1.ShowSave

vStrfilename = CommonDialog1.filename
 
Me.MousePointer = vbHourglass
' get a free handle for the file and open it for output
    vIntFreeHandle = FreeFile
   
    Open vStrfilename For Output As #vIntFreeHandle
    'start New
    Print #vIntFreeHandle, "<?xml version=3.0?>"
    Print #vIntFreeHandle, vbCrLf
    Print #vIntFreeHandle, "<InvoiceFile>"
    Print #vIntFreeHandle, "<fileformat>4.00</fileformat>"
    Print #vIntFreeHandle, "<created>" & Format(Date, "yyyymmdd") & "</created>"
    Print #vIntFreeHandle, vbCrLf
       
    vStrSql = "SELECT * from Client_Invoices"
    If vRsInvoice.State = adStateOpen Then vRsInvoice.Close
    vRsInvoice.Open vStrSql, conn, adOpenStatic, adLockOptimistic, adCmdText
    If vRsInvoice.State = adStateOpen Then
        If vRsInvoice.RecordCount > 0 Then
            vRsInvoice.MoveFirst
            Do While Not vRsInvoice.EOF
                    For Each oField In vRsInvoice.Fields
                        Print #vIntFreeHandle, "<" & oField.Name & ">" & oField.Value & "</" & oField.Name & ">"
                    Next
                    Print #vIntFreeHandle, vbCrLf
                vRsInvoice.MoveNext
            Loop
        End If
    End If
       
    ' close the file
    Print #vIntFreeHandle, "</invoicefile>"
    Close #vIntFreeHandle
Me.MousePointer = vbNormal
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub
Hi chitramahadik,
In VB, go to Project -> References and add a reference to Microsoft XML

Use the XML object to do all of the writing for you!

Dabas
ASKER CERTIFIED SOLUTION
Avatar of monvelasquez
monvelasquez

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi chit, cant you use the Microsoft XML library?

Its extrememly simple to use and the documentation is here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmmscxmlreference.asp

Let me know if you need any help using these interfaces.
CleanupPing:
Suggest points to monvelasquez.
Not worth it to split 35 points

Dabas