Link to home
Start Free TrialLog in
Avatar of khacharn
khacharn

asked on

How to Populate A Combo Box(in HTML) with all the Values From an XML file..

hi all
I am really strugling with XML..that makes me try to learn it even better..
I have this xml file(companies.xml).
****************************************
<?xml version="1.0" ?>
- <companies>
- <company>
  <co_code>20tcen</co_code>
  <co_name>20th Century Finance Corporation Ltd (Merged)</co_name>
  </company>
- <company>
  <co_code>akhtex</co_code>
  <co_name>Akhileshwar Texports Ltd</co_name>
  </company>
- <company>
  <co_code>arcgre</co_code>
  <co_name>Archies Greetings and Gifts Ltd</co_name>
  </company>
- <company>
  <co_code>elgequ</co_code>
  <co_name>Elgi Equipments Ltd</co_name>
  </company>
- <company>
  <co_code>gujvit</co_code>
  <co_name>Gujarat Vita Pharma Ltd</co_name>
  </company>
- <company>
  <co_code>jattex</co_code>
  <co_name>Jatayu Textiles and Industries Ltd</co_name>
  </company>
- <company>
  <co_code>leafin</co_code>
  <co_name>Leasing Finance India Ltd</co_name>
  </company>
- <company>
  <co_code>mefcap</co_code>
  <co_name>Mefcom Capital Markets Ltd</co_name>
  </company>
- <company>
  <co_code>suqdam</co_code>
  <co_name>Sugal and Damani Finlease Ltd</co_name>
  </company>
- <company>
  <co_code>tstanc</co_code>
  <co_name>T Stanes and Company Ltd</co_name>
  </company>
- <company>
  <co_code>viclam</co_code>
  <co_name>Victory Laminations Ltd</co_name>
  </company>
- <company>
  <co_code>yuvint</co_code>
  <co_name>Yuvraj International Ltd</co_name>
  </company>
  </companies>
****************************************
I want to render all the values in this XML file in a Combobox in a simple html page..That is I want to populate all the values in the XML FILE in the combobox.
i am really strugling with the code..Can anyone help me..with it..
Regards
Nitin K
Avatar of BigRat
BigRat
Flag of France image

Post the code you have so far, or at least say with what tool you are trying to process it.
Avatar of khacharn
khacharn

ASKER

hi BigRat..
Here is the code for the .html page in which i am calling the xml file
****************************************
<applet code="com.ms.xml.dso.XMLDSO.class" id="xmldso" mayscript="true" height="1"
width="1">
  <param name="url" value="companies.xml">
</applet>
<html>
<body>

<table DATASRC="#xmldso">
*****problem Area***********************
******This coide does not work*********
<select name="list" rows="3">
      <option value="me" ><span DATAFLD="co_name"></span></option></select>
****************************************
****************************************
  <tr>
    <td><a href=<span DATAFLD="co_code">&nbsp;<span DATAFLD="co_code"></span></a></td>
    <td><span DATAFLD="co_name"></span></td>
  </tr>
</table>

</body>
</html>
***************************************
Please Help ASAP
Regards
Nitin
Why isn't the <select> a row in the table? And what exactly do you get on the screen?
If i put the <select> in the <tr> then it is printed as many times as there are records in the Xml file..

in the xml file there are 10 companies so the select box gets printed in the html file with no values in it..
basically the:
<select name="list" rows="3">
<option value="me" ><span DATAFLD="co_name"></span></option></select>
DOES NOT WORK..
Regards
Nitin
Try the following. assuming xml is loaded as follows :

<XML ID=xmldso>YOUR XML</XML>

function loadcombo()
{
var c;

for(c in xmldso.documentElement.childNodes)
{
    opt = document.createElement("OPTION");
    opt.value = c.selectSingleNode("co_code").text;
    opt.text = c.selectSingleNode("co_name").text;
    combo.options.add(opt);
}

WHERE combo is the name of your combo box.

I haven't tested the code for errors, but the principle definitely works. I have used it a number of times.

Regards
Gavin
ASKER CERTIFIED SOLUTION
Avatar of AlanB082898
AlanB082898

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The microsoft url I listed in the answer doesn't work. It should be http://msdn.microsoft.com/workshop/c-frame.htm?950744713098#/workshop/author/databind/dataconsumer.asp and search for "select element"
note: I know its probably obvious but step 1 in the answer refers to the XML file.
HI all..
Thanx for all the help
Last Question
I have a
1) try.xml file
2) try.xsl file
I want to ccreate a new virtual document using both these
I tried calling both of these in an xml file but my syntax does not work..
CAN YOU HELP ME..
PLEASE REPLY ASAP
regards
Nitin