Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to fill a combo using XML !

Posted on 2002-03-04
10
Medium Priority
?
378 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
[X]
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
10 Comments
 
LVL 27

Expert Comment

by:BigRat
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">
</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
ID: 6842442
ping
0
 

Author Comment

by:qaziasif
ID: 6843747
Microsoft Q258295, is of great help but I want to use the XML data island through VB not through ASP ???
regards,
Asif
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:BigRat
ID: 6843923
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
 
LVL 2

Expert Comment

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

Regards,
Carl
0
 

Author Comment

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

0
 
LVL 2

Accepted Solution

by:
Carlovski earned 100 total points
ID: 6877085
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
ID: 6877121
Let me try that.
Thanks,
Qazi
0
 
LVL 9

Expert Comment

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

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

>S'Plug<
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

597 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