Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reading XML Data in VB6

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 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