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
<comment confermato="true" timestamp="20130627112554">
<comment confermato="false" timestamp="20130903225513">
<comment confermato="false" timestamp="20130904191337">
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
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']";
my $commento = $root->findnodes("$nodetobefound") || die("dead3");
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,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||