?
Solved

Create file in xml format using visual basic 6.0

Posted on 2003-11-09
11
Medium Priority
?
1,813 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 140 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

777 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