How to fill a combo using XML !

Posted on 2002-03-04
Last Modified: 2008-02-01
I have never used XML but now I need to fill my combo in a project, at the client end using XML. The reason of thinking XML for this purpose is to save the network trip inorder to fill the combo, which can impact the efficency of the software.
The front end of the application is in VB, so I have following questions..

1. How I can put my data in XML on client side(lets assume its a two column table like Product_ID and Product_Name)

2. How I would access this XML Data to fill the combo box.

3. How I will update the XML file incase of any addition to the products list.

Question by:qaziasif
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
  • 3
  • 2
  • 2
  • +2
LVL 27

Expert Comment

ID: 6839116
This can be done simply in IE by using an XML Data Island and refering to this in the <SELECT> box eg:

<XML SRC="getmydata.asp" ID="list1"></XML>

<SELECT DATASRC="#list1" DATAFLD="product">

The simplest thing to do is to generate the XML for the data island directly from the database. (See Microsoft Q258295).

Expert Comment

ID: 6842442

Author Comment

ID: 6843747
Microsoft Q258295, is of great help but I want to use the XML data island through VB not through ASP ???
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

LVL 27

Expert Comment

ID: 6843923

Well your going to have to create an MSXML object, set async to false, load the XML text file into it, and execute something like :-
      list = object.selectNodes('/root/product');

<?xml .....?>

list is then a NodeList object which contains a standard VB iterator, each node (item) in the list is a <product> Node. If you then do
you'll get the text part for each node in turn. With the texts for the Product_Name and Product_Id you then fill your Combo.

(Sorry: but I do not hack VB, only JavaScript :)

Expert Comment

ID: 6876511
I don't know how using XML will save a network trip, You still have to get the data from somewhere. Unless you hold the XML locally, either in memory or in a file system, and reuse it. But then you will have to handle the refreshing of the file, which means either a regular (hourly/daily etc) update, which could result in getting out of date, or have something driven from the server, which sends an update when data is added. This could easily get messy.

How many client machines are you talking about?
How often will the lookup data be updated?
How much does a network trip slow down the system?
I can supply you with the outline code to load the combo box with the XML, but depending on the answers to the above, I am not sure if this will be your best solution.


Author Comment

ID: 6876554
Carl! Thanks for the comment.

Yes, I am planning to save the network trip by putting the data on the client.Your questions are very genuine but the reality is that incase of dail-up we have to face serious delay problems here in our country.
The number of clients are round about 30.
As far as the updation is concern the data I want toput on client would have new values rarely e.g the no. of items a compnay is producing, so I can afford the updation once in a day.
If I go for populating the combos from the server then each time the end user made a transaction, the combo has to fill from the server which will dafinatley make it slow.

waiting for ur code :)
Best Regards,


Accepted Solution

Carlovski earned 25 total points
ID: 6877085
Assuming that you can handle updating the xml on a regular basis (Probably easiest to just replace each time, adding and deleting nodes might get complicated)

Private Sub FillCombo()
    Dim strXMLLocation As String
    Dim objXML As MSXML2.DOMDocument
    Dim objNodeList As MSXML2.IXMLDOMNodeList
    Dim objAnElement As MSXML2.IXMLDOMElement
    Set objXML = New MSXML2.DOMDocument
     strXMLLocation = "C:\MyFolder\MyXML.xml"    
     objXML.async = False
     objXML.load strXMLLocation
        Set objNodeLists = objXML.selectNodes("/Products/Product")
        For Each objAnElement In objNodeList
            Mycbo.AddItem objAnElement.getAttribute("ProductName")
            Mycbo.ItemData(Mycbo.NewIndex) = CLng(objAnElement.getAttribute("ProductID"))
        Set objNodeList = Nothing
    End If
    Set objXML = Nothing
    Exit Sub
This was a bit cobbled together from something I had written previously, I used it from a database though.
It expects the xml to be in the format
  <Product ProductID='1' ProductName='Fish Fingers'/>
  <Product ProductID='2' ProductName='Bananas'/>

The basic idea is that you loop through the xml document, and extract the values from each node, and append them to the items collection of the combo box.

Author Comment

ID: 6877121
Let me try that.

Expert Comment

ID: 8730551
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[Accept Carlovski's comment as answer.]
Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL ( and MongoDB (…
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…

688 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