Solved

Reading XML Data in VB6

Posted on 2004-09-22
3
29,661 Views
Last Modified: 2011-08-18
I have an application. From application API I can define an interface to my VB DLL (for example: myDLL.myClass.myfunction)
From my application, I can select table and its columns to be used by myDLL
The data is exchanged in XML format.

I want to read this XML file/data using my function:  Public Function myFunction(sXML As String) As Variant
This function -
-  reads XML date for tablename, column ID and corresponding column data
-  can I assign XML data to a string variable in VB?

Can you help with sample code? I want to create DLL

--------------------------------
XML format:

<XML>
<DataCache USerid = "userid" username = "username">
<tablename1>
<columnname>colum value</columnname>
<columnname>colum value</columnname>
...
..
</tablename1>
<tablename2>
<columnname>colum value</columnname>
<columnname>colum value</columnname>
...
..
</tablename2>
...
..
</DataCache>
</XML>
-------------------------------
0
Comment
Question by:Vasi04
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
You use the XML DOM for working with XML in VB.  Under Project > References, check "Microsoft XML, v4.0".

As far as code goes, something like the following should get you started:

Public Function myFunction(ByVal sXML As String) As Variant

    Dim oDom As New MSXML2.DOMDocument40
    Dim oTables As IXMLDomNodeList
    Dim oChild As IXMLDomNode
    Dim bOK As Boolean

    '// Load xml into Dom object
    bOK = oDom.loadXML(sXML)

    If bOK Then
       
        '// Get all tablename nodes
        Set oNodes = oDom.selectNodes("//DataCache/*")

        '// Loop through each table node
        For Each oChild In oNodes

             '// Code to process any nodes your interested in

        Next oChild

    Else
        '// Something was wrong with the passed in XML
    End If

End Function


This should at least get you started.

Hope this helps.
0
 

Author Comment

by:Vasi04
Comment Utility
Thanks carl_tawn
Can I read individual field of a table and store it in a variable?
Can I delete fields and rows of a table and update value for a table to XML?
cheers
0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
Both of those things are fairly simple.  Each node has a childNodes collection, so in the for each loop you can access the childnodes collection for the table and manipulate each element.

I would recommend heading to http://msdn.microsoft.com and downloading the XML SDK, it has a full reference for the XML Dom with worked examples in different languages.

Hope this helps.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now