XML-Parser for perl - How to work in windows environment.

How to download and set upthe XML::parser module. I am working in Windows 98 environment and using Active perl 5. Can any one help me by giving guidelines for Download and setup the module for windows environment. If it is not possible for windows environment, how can I download for UNIX environment?
 
gnagabandiAsked:
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.

KennyIT Application ExecutiveCommented:
0
prakashk021799Commented:
If you are running ActivePerl, XML::Parser is already installed for you. The PPM script in ActivePerl distribution needs it. Hence the module is bundled in the distribution.

For Unix, go to any CPAN archive.  Or, visit <http://search.cpan.org/search?dist=XML-Parser>

If you are directly connected to the Net, you can also use the CPAN module to install the module for you (provided you have necessary permissions). Just do at the command prompt:

perl -MCPAN -e shell

You will get the CPAN> prompt. If you are doing it for the fitst time, you will be asked a bunch of questions. After that at the CPAN> prompt,

CPAN> install XML::Parser

The module is downloaded and installed for you.

Type help at the prompt to see all the commands available in CPAN shell.
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
gnagabandiAuthor Commented:
Thankyou very much prakash. But Iam not getting any sample scripts regarding how to use XML parser. My task is I have one XML file which contains the username and passwords. My CGI/Perl program takes the username and password from the client/user and checks the existence of that user in the XML file. If the user and password is present in the XML file then my perl do some other tasks.

Can You have any Idia or sample script regarding the above task. If you know any reference please help me.

Thanks inadvance for the help.
0
prakashk021799Commented:
Here's a very bare-bones example. But it should give you some idea.

Assuming the password file is in this format:

<passwords>
    <user>
      <name>happy</name>
      <pass>sad</pass>
    </user>
    <user>
      <name>dopey</name>
      <pass>smart</pass>
    </user>
    <user>
      <name>doc</name>
      <pass>patient</pass>
    </user>
    <user>
      <name>sneezy</name>
      <pass>chirpy</pass>
    </user>
    <user>
      <name>bashful</name>
      <pass>noway</pass>
    </user>
</passwords>


Here's the script. Run it with three arguments: password file name, user name and password to check for.

#!/usr/local/bin/perl -w

use XML::Parser;

my ($file, $input_user, $input_pass) = @ARGV;

$xp = new XML::Parser(Handlers => {Start => \&start_handler,
                                   End   => \&end_handler,
                                   Char  => \&char_handler});

die "can't create XML::Parser object; $!\n"
    unless $xp;

my $found = undef;
$xp->parsefile($file);

if ($found) {
    print "Welcome, $input_user!\n";
} else {
    print "Sorry, $input_user!\n";
}

sub start_handler
{
    my ($xp, $elem) = @_;

#    print "Start: $elem\n";
    if ($elem eq 'name') {
        $user_seen = 1;
    } elsif ($elem eq 'pass') {
        $pass_seen = 1;
    }
}

sub end_handler
{
    my ($xp, $elem) = @_;

#    print "End: $elem\n";
    if ($elem eq 'name') {
        $user_seen = 0;
    } elsif ($elem eq 'pass') {
        $pass_seen = 0;
    }
}

sub char_handler
{
    my ($xp, $str) = @_;

#    print "    Value: $str\n";
    if ($user_seen) {
        $curr_user = $str;
    } elsif ($pass_seen) {
        $curr_pass = $str;
        check_pass($curr_user, $curr_pass)
            unless ($found);
    }
}

sub check_pass
{
    my ($user, $pass) = @_;

#    print "Checking $user/$pass against $input_user/$input_pass ...\n";
    $found = $user eq $input_user and $pass eq $input_pass;
}



Hope that helps.
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
Perl

From novice to tech pro — start learning today.