• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1619
  • Last Modified:

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?
 
0
gnagabandi
Asked:
gnagabandi
  • 2
1 Solution
 
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
 
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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