vikrammohan has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get the values of the dropdown box in HTML from XML tag attribute, with Perl script. This is a HTML based application, will be run on one windows server Internet explorer locally. Both the HTML and XML will be on server hard disk before running. I have problem getting the XML and also getting the XML tag attribute into the drop down box. Here is my XML file:

<States> <State Name="North" Server="Server1" Backupserver="BKserver1"></State> <State Name="South" Server="Server2" Backupserver="BKserver2"></State> <State Name="East" Server="Server3" Backupserver="BKserver3"></State> ........ </States>

Here is my HTML part:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 5.0 Transitional//EN"> <html> <head><title>Get Dropdown from XML using Perlscript</title></head> <body> ......... <select id="States" name="States"> <option></option> <script language="perlscript"> use strict; use warnings; use feature 'say'; use XML::XPath; my $xp = XML::XPath->new(filename => 'State.xml'); my $queries = 'States/State'; $nodeset = $xp->find($queries); foreach $mynode ($nodeset->get_nodelist) { my $statename = $mynode->getAttribute('Name'); $window->document->write("<option value='".$statename."'>". +$statename."</option>"); } </script> </select> ..... </body> </html>

I am newbie to perl scripting and using the above Perlscrip to open the XML and populating the XML but it fails. I am not sure where it fails and how to correct it to make it work. All I want is the Dropdown box with ID "States" to have the value "North","South","East",.... while the page loads. Have crafted the above PerlScript from various other posts. These HTML and XML are in the same folder on the windows server and are opened in IE by user, while running this HTML application. Can someone help me with a solution to achieve this problem? Thank you

Replies are listed 'Best First'.
Re: Perl Script to populate Dropdown box from XML Attributes
by hippo (Archbishop) on Nov 22, 2016 at 21:59 UTC

    As of 2016, Perl is still not widely supported by browsers as a client-side scripting language. I fear you are going to have to rethink your approach here. Either use Perl on the server side before sending the document to the browser or else consider some other language to do it on the client side.

      Client-side server has Active perl installed in it, so we don't have any problem running Perl Script on the browser. So can you help me achieve this with Perl Script? Thanks!

        my $xp = XML::XPath->new(filename => 'State.xml');

        I doubt that the file State.xml is available on the client, where the code runs.

        Or even if that file is on the client, you will need to specify the full path to it, and even then I doubt that the Internet Explorer scripting sandbox will easily allow access to the file.

        Client-side Server
        … sounds like an Oxymoron to me (except if you're using Terminal Servers or some such). Perhaps you should elaborate on your setup.

        PerlScript documentation says it's an optional component, so, even if ActivePerl is installed, PerlScript might not. That documentation page also contains an example "Client-side PerlScript". Does that work?