in reply to Can't read xml after linking schema
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my ($userok, $passok) = (1, 0); my $digestuser = 'dado'; my $digestpass = 'cane'; my $file = 'user.xml'; my $parser = 'XML::LibXML'->new; my $doc = $parser->parse_file($file); my $root = $doc->getDocumentElement; my $xpc = 'XML::LibXML::XPathContext'->new; $xpc->registerNs('p', 'http://www.progetto.com'); for my $u ($xpc->findnodes('p:userlist/p:user', $doc)) { print "inside-cycle"; my ($property) = $xpc->findnodes('p:username', $u); if ($property->textContent eq $digestuser) { print $userok; ($property) = $xpc->findnodes('p:password', $u); if ($property->textContent eq $digestpass) { $passok = 1; print "i did it"; } last } }
The wrapper XML::XSH2 simplifies the code to
open user.xml ; my $digestuser = 'dado' ; my $password = 'cane' ; my $passok ; if p:userlist/p:user[p:username=$digestuser and p:password=$digestpass +] $passok = 1 ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't read xml after linking schema
by njack (Novice) on Jan 28, 2014 at 16:07 UTC | |
by choroba (Cardinal) on Jan 28, 2014 at 16:26 UTC | |
|
Re^2: Can't read xml after linking schema
by njack (Novice) on Jan 28, 2014 at 16:15 UTC | |
by choroba (Cardinal) on Jan 28, 2014 at 16:22 UTC |