Mark thank you very much for that. This is definitely
getting me on the
right road and looks like I can whip something up today.
Question though
when I do a:
Foreach my $install (x->findnodes('//InstallInfo'))
{
}
Inside that foreach loop I want to check each item inside of
the
InstallInfo node and do certain conditions if I see certain
nodes. Now
to accomplish this how do I compare $install? Can I do
something like
if($install eq "something") or do I have to
convert $install to
something? Is it possible to use Regex in some cases as
well? It looks
like in worse case scenario I could do ->toString but
then I lose the
whole advantage of having well formed and defined data.
Thanks
-----Original Message-----
From: Thomas, Mark - BLS CTR [mailto:Thomas.Mark bls.gov]
Sent: Monday, May 22, 2006 6:16 AM
To: Mesdaq, Ali; perl-xml listserv.ActiveState.com
Subject: RE: xml beginner
Ali,
Here is some sample code that works on your XML string:
use XML::XPath;
my $x = XML::XPath->new(xml=>$xml);
foreach my $install ($x->findnodes('//InstallInfo')){
#extract name
printf "Name: %s\n",
$install->findvalue('InstallDetection/ InstallName');
#you can even grab the date from the parent tag
printf "Date: %s\n",
$install->findvalue('ancestor::Installlog/ Date');
}
Grant's suggestion of XML::LibXML is an excellent one, and
that is the
module I prefer to use in most cases. The code above would
work on an
XML::LibXML object as well.
One caveat is that these are DOM-based modules, which parse
the document
in memory. If you have an extremely large document and
building a DOM
would exceed your available RAM, you may want to use
XML::Twig instead.
--
Mark Thomas
Internet Systems Architect
_______________________________________
BAE SYSTEMS Information Technology
2525 Network Place
Herndon, VA 20171 USA
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|