Solved

How to fill a combo using XML !

Posted on 2002-03-04
10
327 Views
Last Modified: 2008-02-01
Hi,
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.

Regards,
Asif
 
0
Comment
Question by:qaziasif
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 27

Expert Comment

by:BigRat
Comment Utility
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">
</SELECT>

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

Expert Comment

by:kfehriba
Comment Utility
ping
0
 

Author Comment

by:qaziasif
Comment Utility
Microsoft Q258295, is of great help but I want to use the XML data island through VB not through ASP ???
regards,
Asif
0
 
LVL 27

Expert Comment

by:BigRat
Comment Utility
Oh!

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 .....?>
<root>
   <product>
      <Product_Id>1234</Product_Id>
      <Product_Name>.....</Product_Name>
      .........
   </product>
</root>

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
     node.selectSingleNode('./Prouct_Name').text
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 :)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 2

Expert Comment

by:Carlovski
Comment Utility
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.

Regards,
Carl
0
 

Author Comment

by:qaziasif
Comment Utility
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,
Qazi

0
 
LVL 2

Accepted Solution

by:
Carlovski earned 25 total points
Comment Utility
O.k
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"))
        Next
        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
<Products>
  <Product ProductID='1' ProductName='Fish Fingers'/>
  <Product ProductID='2' ProductName='Bananas'/>
....
...
</Products>

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.
0
 

Author Comment

by:qaziasif
Comment Utility
Let me try that.
Thanks,
Qazi
0
 
LVL 9

Expert Comment

by:sparkplug
Comment Utility
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

>S'Plug<
EE Cleanup Volunteer
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

12 Experts available now in Live!

Get 1:1 Help Now