Solved

Create file in xml format using visual basic 6.0

Posted on 2003-11-09
11
1,811 Views
Last Modified: 2013-11-25
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.....
0
Comment
Question by:chitramahadik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 1

Expert Comment

by:JonothanTompson
ID: 9712432
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
0
 

Author Comment

by:chitramahadik
ID: 9712439
Can u give me any example for the same ,so I can understand the same well
0
 
LVL 3

Expert Comment

by:monvelasquez
ID: 9712451
yes it's just the same.... just give them an xml extension
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:chitramahadik
ID: 9712541
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
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9712649
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
0
 
LVL 3

Accepted Solution

by:
monvelasquez earned 35 total points
ID: 9712662
this line

Print #vIntFreeHandle, "<?xml version=3.0?>"

should be..

Print #vIntFreeHandle, "<?xml version=""3.0""?>"

all values of the attributes should be enclosed in "quotes"
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9716284
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.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10163618
CleanupPing:
Suggest points to monvelasquez.
Not worth it to split 35 points

Dabas
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 70
Authentication of Web Services 3 98
MsgBox 4 71
Error with a code discussed on this page 5 39
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question