Hello everybody, i think i have a simple question but i can't find an aswer to it anywhere so i hope you can help.
I have an xml file with namespace and i want to select a node with an attribute with a specific value.
Here is the xml file:
<?xml version="1.0" encoding="UTF-8"?> <guestbook xmlns="http://myweb.com" xmlns:xs="http://www.w3.org/2001/X +MLSchema-instance" nome="740" xs:schemaLocation="http://myweb.com gue +stbook.xsd"> <comment confermato="true" timestamp="20130627112554"> <guest>...</guest> </comment> <comment confermato="false" timestamp="20130903225513"> <guest>...</guest> </comment> <comment confermato="false" timestamp="20130904191337"> <guest>...</guest> </comment> </guestbook>
I need, with a cgi script, to select the node "comment" with the timestamp "20130903225513". The problem is that i don't know hot to put the namespace correctly. Here is the code for the script
#!/usr/bin/perl use strict; use XML::LibXML; use HTML::Entities; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use Fcntl qw(:flock); my $cgi = new CGI; print "Content-type: text/html\n\n"; my $file_dati = "../data/xml/guestbook_xml.xml"; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($file_dati) || die("dead1"); my $root = $doc->getDocumentElement || die("dead2"); my $nodetobefound= "xs:commento[xs:\@timestamp='20130903225513']"; print "$nodetobefound\n"; my $commento = $root->findnodes("$nodetobefound") || die("dead3"); print $commento->get_node(0)->toString();
If i don't insert any namespace in the query i finish in the "dead3" die, if i put any kind of namespace i receive an "Xpath error: invalid expression".
Any hint on how to write the correct xpath query?
thanx in advance,
Giulia
In reply to How to write an xpath query including attributes for an XML with namespace by topola1882
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |