Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create file in xml format using visual basic 6.0

Posted on 2003-11-09
11
Medium Priority
?
1,814 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

604 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