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
  • 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 ???
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 :)
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML Paring  Error - Premature end of file. 7 77
Change to event 1 100
How to read XML file attributes... 17 52
XML filtering Windows Event Viewer 10 45
Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now