krujos has asked for the wisdom of the Perl Monks concerning the following question:
what I am trying to do is get the values between the elements named username and password in the xml document which looks like this.#!/usr/bin/perl use strict; use warnings; use CGI qw ( :standard ); use Fcntl qw ( :flock ); use XML::Parser; if (param) { my ($parser, $document, $users); open(USERS, "../../xml_final/users/users.xml") || die "Could not open users.xml $!"; flock(USERS, LOCK_SH); print header; print start_html; $parser= new XML::Parser(); $parser->setHandlers( Start => \&start_handler, #End => \&end_handler, $document = $parser->parse (\*USERS); close (USERS); sub start_handler{ my ($expat, $element, %attributes) =@_; my ($flag); $flag=0; if ($flag==0 && $element eq param("username")) { $flag=1; } if ($flag==1 && $element eq param("password")) { print p("Good Job"); } }
<?xml version ="1.0"?> <users> <user> <name>Joshua</name> <username>user</username> <password>pass</password> </user> </users>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I get the text value of an element using XML Parser?
by Anonymous Monk on Jan 26, 2002 at 08:01 UTC | |
|
Re: How do I get the text value of an element using XML Parser?
by mirod (Canon) on Jan 26, 2002 at 13:51 UTC |