Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading XML Data in VB6

Posted on 2004-09-22
3
Medium Priority
?
29,778 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

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