Solved

Reading XML Data in VB6

Posted on 2004-09-22
3
29,752 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
[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
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 12122276
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
ID: 12122588
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
ID: 12122682
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 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