spstansbury has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to extract some information from xml report generated by a trouble ticket system.
I have an "incident" number, and want to extract additional information from that node.
The script looks like this:
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; use XML::LibXML::XPathContext; my $file = "./incident.xml"; my $parser = XML::LibXML->new(XML_LIBXML_RECOVER => 2); $parser->recover_silently(1); my $dom = $parser->load_xml( location => $file ); my $root = $dom->getDocumentElement(); my $xpc = XML::LibXML::XPathContext->new($root); ############################################## # If we have an incident ticket reference get info from that ticket. my $inc_node = $xpc->findnodes('/upload/incident[number/text() = "INC9 +02531"]'); my $service_restoration_time = $xpc->findvalue( "./u_service_restorati +on_time", $inc_node ); my $assignment_group = $xpc->findvalue( ".//assignment_group/\@display +_value", $inc_node ); # etc... print $service_restoration_time . "\n" ; print $assignment_group . "\n" ;
The XML file that the script parses looks like this (shortened, has thousands of incident entries. There is no namespace declared, not sure how to handle that...
I'm getting "XPathContext: lost current node at ./query_test.pl line 23" as the error.
<?xml version="1.0" encoding="UTF-8"?> <unload unload_date="2010-03-17 13:02:24"> <incident action="INSERT_OR_UPDATE"> <opened_at>2009-12-15 14:29:55</opened_at> <closed_at>2009-12-21 05:00:21</closed_at> <u_problem_summary/> <u_item>none</u_item> <business_duration>1970-01-03 05:30:05</business_duration> <category>none</category> <number>INC902550</number> <u_caller_location/> <u_service_restoration_time>2009-12-15 23:01:17</u_service_restoration +_time> <u_close_code>Service Restored</u_close_code> <u_service_loss_time>2009-12-15 14:29:55</u_service_loss_time> <u_user_issue>Software Issue/Bug</u_user_issue> <element_id>92becbd70a0a140b0187537b8516f18c</element_id> </unload>
Would greatly appreciate being pointed in the right direction!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML parsing help need, please...
by ikegami (Patriarch) on Apr 13, 2010 at 20:31 UTC | |
by spstansbury (Monk) on Apr 13, 2010 at 22:15 UTC | |
|
Re: XML parsing help need, please...
by ikegami (Patriarch) on Apr 13, 2010 at 20:38 UTC | |
by spstansbury (Monk) on Apr 13, 2010 at 22:17 UTC | |
|
Re: XML parsing help need, please...
by amedico (Sexton) on Apr 13, 2010 at 21:23 UTC | |
by spstansbury (Monk) on Apr 13, 2010 at 22:18 UTC |