#!/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 ;
In reply to Re: Can't read xml after linking schema
by choroba
in thread Can't read xml after linking schema
by njack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |