Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to parse an XML file with VB6, don't understand how to do this...

4 views
Skip to first unread message

Raphaël Schmid

unread,
Oct 25, 2003, 10:23:45 AM10/25/03
to

Hello!

I need some help to parse an XML file with VB6.

I would like to parse an XML file, then display the informations of that XML file in a listbox. Then from this listbox, when I select a line, the elements of this line are displayed in some textboxes, to be able to modify each element.

An example:

I've got a file named : clients.xml:

<?xml version="1.0" encoding="UTF-8"?>
<clients>
    <client id="1">
        <nom>nicolas Ray</nom>
        <prenom>nicolas</prenom>
        <login>NRAY</login>
        <password>NRAY</password>
        <categorie>Masculin</categorie>
        <email>nico...@hotmail.com</email>
        <telephone>0223664422</telephone>
        <adresse>ch.des cigarettes</adresse>
        <npa>1007</npa>
        <Ville>Lausanne</Ville>
    </client>
    <client id="2">
        <nom>raphael schmid</nom>
        <prenom>raphael</prenom>
        <login>RSCH</login>
        <password>RSCH</password>
        <categorie>Masculin</categorie>
        <email>smas...@hotmail.com</email>
        <telephone>0223642266</telephone>
        <adresse>domaine</adresse>
        <npa>1260</npa>
        <Ville>Nyon</Ville>
    </client>
    <client id="4">
        <nom>Bernard Morin</nom>
        <prenom>Bernard</prenom>
        <login>subalashi</login>
        <password>caisson</password>
        <categorie>Masculin</categorie>
        <email/>
        <telephone/>
        <adresse>Broadway</adresse>
        <npa>75000</npa>
        <Ville>Paris</Ville>
    </client>
    <client id="3">
        <nom>meyer david</nom>
        <prenom>meyer</prenom>
        <login>David</login>
        <password>meyer</password>
        <categorie>Masculin</categorie>
        <email>lord_b...@hotmail.com</email>
        <telephone>5454</telephone>
        <adresse>av du grey 78</adresse>
        <npa>1018</npa>
        <Ville>lausanne</Ville>
    </client>
    <client id="5">
        <nom>asd sd</nom>
        <prenom>asd</prenom>
        <login>asd</login>
        <password>asd</password>
        <categorie>Feminin</categorie>
        <email>ad</email>
        <telephone>ad</telephone>
        <adresse>asd</adresse>
        <npa>asd</npa>
        <Ville>ad</Ville>
    </client>
    <client id="6">
        <nom>Bobo Bobo</nom>
        <prenom>Bobo</prenom>
        <login>Bobo</login>
        <password>Bobo</password>
        <categorie>Masculin</categorie>
        <email>Bobo</email>
        <telephone>Bobo</telephone>
        <adresse>Bobo</adresse>
        <npa>Bobo</npa>
        <Ville>Bobo</Ville>
    </client>
</clients>

So I want that this file is displayed in a listbox, ant that each line have this appeareance:

id nom prenom login password categorie email telephone adresse npa ville

And when I click on a line, it displays each element of that line in a textbox, the id, the name, the first name, and so on..

That would be 11 textboxes

I've tried to find a tutorial showing me how to do this, but I haven't found something like that so far..and I admit that I'm a newbie to VB...

Could somebody help me please and show me the code to do this? I begin to desesparate....:-(

Any help will be greatly appreciated!

Thank you very much!

Raph

P.S. Sorry for my poor english...

Andres Rojas

unread,
Oct 25, 2003, 11:49:23 AM10/25/03
to

Dear Raph:

You need first to Reference de msxml 3 in your VB 6 Project
then you can declare your xml variables object and use the
properties and methods. I am develop with vb6 and xml
now. I send you part of mi code.

'*************************************************
'*******Declare variables XML ********************

Dim XmlDoc As DOMDocument30
Dim XmlElem As IXMLDOMElement
Dim XmlElem2 As IXMLDOMElement
Dim XmlParametroX As IXMLDOMElement
Dim XmlAtt As IXMLDOMNamedNodeMap
Dim XmlNode As IXMLDOMNode
Dim XmlNode2 As IXMLDOMNode
Dim XmlNode3 As IXMLDOMNode
Dim XmlNode4 As IXMLDOMNode
Dim Att As IXMLDOMAttribute
Dim XmlNodeListParams As IXMLDOMNodeList

Set XmlDoc = New DOMDocument

If pXml <> "" Then
Res = XmlDoc.loadXML(pXml) ' Load from string in
xml format
Else
Res = XmlDoc.Load(XmlFile) ' load from xml file
End If

If Not Res Then
' Your error trapper
Exit Function
End If

Set XmlNode = XmlDoc.selectSingleNode("MSG")

Set XmlElem2 = XmlNode.firstChild
With pReg
.CORREL = XmlElem2.getAttribute("CORREL")
.ANI = XmlElem2.getAttribute("ANI")
.CIA = XmlElem2.getAttribute("CIA")
.DATO = XmlElem2.getAttribute("DATO")
.DNI = XmlElem2.getAttribute("DNI")
.FECHA = XmlElem2.getAttribute("FECHA")
.MENSAJE = XmlElem2.getAttribute("MENSAJE")
End With
'****************************************

This is a little show to use xml with vb6, you must to try
with other methods of the object.

Bye and I wait that the example help you

Bye

ANDRES ROJAS from Chile
aru...@hotmail.com

Raphaël Schmid

unread,
Oct 26, 2003, 10:20:05 AM10/26/03
to
Thanks for your answer Andres!
I will try this!

Have a nice day!

Raph


0 new messages