I have tired with your code but not getting expected result . My samlple.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <event_list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmln +s:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.hp.com/2009 +/software/opr/data_model" total_size="34" page_size="20" start_index= +"1" self="https://testurl/event_list?query=title+LIKE+%22PROBING%2810 +0%29%2425%22" type="urn:x-hp:2009:software:data_model:opr:type:event_ +list" version="1.1"> <drilldown_url> https://testurl/opr-web/opr-evt-browser</drilldown_url> <event relationships_included="true" self="https://testurl/event_l +ist/031c3c70-4ace-71e7-0b5b-88fb83170000" type="urn:x-hp:2009:softwar +e:data_model:opr:type:event" version="1.3"> <state> open</state> <severity> critical</severity> <priority> medium</priority> <category> SAR_OP_Service</category> <application> business_transaction_group</application> <time_created> 2017-06-06T15:37:13Z</time_created> <time_changed> 2017-06-20T10:37:20.098Z</time_changed> <time_received> 2017-06-20T10:37:20.156Z</time_received> <time_first_received> 2017-06-06T15:37:17.414Z</time_first_received> <custom_attribute_list self="https://testurl/event_list/031c3c +70-4ace-71e7-0b5b-88fb83170000/custom_attribute_list" type="urn:x-hp: +2009:software:data_model:opr:type:event:custom_attribute_list" versio +n="1.0"> <custom_attribute self="https://testurl/event_list/031c3c7 +0-4ace-71e7-0b5b-88fb83170000/custom_attribute_list/SAR_RemedyInciden +t" type="urn:x-hp:2009:software:data_model:opr:type:event:custom_attr +ibute" version="1.0"> <name> SAR_RemedyIncident</name> <value> INC000018745375</value> </custom_attribute> <custom_attribute self="https://testurl/event_list/031c3c7 +0-4ace-71e7-0b5b-88fb83170000/custom_attribute_list/SAR_RemedyQueue" +type="urn:x-hp:2009:software:data_model:opr:type:event:custom_attribu +te" version="1.0"> <name> SAR_RemedyQueue</name> <value> Coll@borate-L3</value> </custom_attribute> <custom_attribute self="https://testurl/event_list/031c3c7 +0-4ace-71e7-0b5b-88fb83170000/custom_attribute_list/SAR_RemedyStatus" + type="urn:x-hp:2009:software:data_model:opr:type:event:custom_attrib +ute" version="1.0"> <name> SAR_RemedyStatus</name> <value> Assigned</value> </custom_attribute> <custom_attribute self="https://testurl/event_list/031c3c7 +0-4ace-71e7-0b5b-88fb83170000/custom_attribute_list/SAR_SSRID" type=" +urn:x-hp:2009:software:data_model:opr:type:event:custom_attribute" ve +rsion="1.0"> <name> SAR_SSRID</name> <value> 957</value> </custom_attribute> <custom_attribute self="https://testurl/event_list/031c3c7 +0-4ace-71e7-0b5b-88fb83170000/custom_attribute_list/Service%20Name" t +ype="urn:x-hp:2009:software:data_model:opr:type:event:custom_attribut +e" version="1.0"> <name> Service Name</name> <value> IPT</value> </custom_attribute> </custom_attribute_list> <time_created_label> 6/6/2017 03:37:13 PM</time_created_label> <time_changed_label> 6/20/2017 10:37:20 AM</time_changed_label> <time_received_label> 6/20/2017 10:37:20 AM</time_received_label> <time_first_received_label> 6/6/2017 03:37:17 PM</time_first_received_label> </event> </event_list>
Suggested code @haukex
#!/usr/bin/perl use warnings; use strict; use XML::XPath; my $file = 'C:/Users/snehit.rahate/Perl/events.xml'; my $xpath = q{//custom_attribute_list/custom_attribute[name='Service N +ame']/value}; # return no result my $xp = XML::XPath->new(filename=>$file); my $nodeset = $xp->find($xpath); for my $node ($nodeset->get_nodelist) { print " XML::XPath: ",$node->string_value,"\n"; }
I want to concatenate service name and slb_ssrid into one value $appname as shown in below.xml .But not able to fetch the value of tag <name> Service Name</name> my $appname = IPT(957) Please suggest and correct me i am wrong. Thanks a Ton !

In reply to Re^2: get specific value of element using xpath in perl by snehit.ar
in thread get specific value of element using xpath in perl by snehit.ar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.