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
khacharnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BigRatCommented:
Post the code you have so far, or at least say with what tool you are trying to process it.
0
khacharnAuthor Commented:
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
0
BigRatCommented:
Why isn't the <select> a row in the table? And what exactly do you get on the screen?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

khacharnAuthor Commented:
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
0
gavindewCommented:
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
0
AlanB082898Commented:
You can do this by applying XSL to your XML.

1. Add <?xml-stylesheet type="text/xsl" href="companies.xsl" ?> below the <?xml version="1.0" ?> line.

2. Use this XSL file (save it as companies.xsl to match above)

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>
  <xsl:template match="companies">
    <html>
      <head>
        <title>Companies</title>
      </head>
      <body>
        <center>
          <h4> Companies</h4>
        </center>
        <select>
          <xsl:apply-templates />
        </select>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="company">
    <option value="me"/>
    <xsl:value-of select="co_name" />
  </xsl:template>
</xsl:stylesheet>

3. Double click on your the companies.xml file.

You should see a ComboBox in a simple HTML page. I did when I tested it under IE 5.

note: The code you were trying to use (data binding) works great for filling a table but it won't fill a select. It will just allow you to set which item in the list is selected. see http://msdn.microsoft.com/workshop/c-frame.htm#/workshop/author/default.asp and search for select on the page.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlanB082898Commented:
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.
0
khacharnAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.