Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

How to fill a combo using XML !

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
qaziasif
Asked:
qaziasif
  • 3
  • 2
  • 2
  • +2
1 Solution
 
BigRatCommented:
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
 
kfehribaCommented:
ping
0
 
qaziasifAuthor Commented:
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!

 
BigRatCommented:
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
 
CarlovskiCommented:
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
 
qaziasifAuthor Commented:
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
 
CarlovskiCommented:
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
 
qaziasifAuthor Commented:
Let me try that.
Thanks,
Qazi
0
 
sparkplugCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now