i have a variable having xml data in it.

$xml = "<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="/templates/xsl/abc/search/searc +hRetrieveResponse.xsl"?><searchRetrieveResponse xmlns="http://www.abc +/srw/"> <version>1.1</version> <numberOfRecords>14135</numberOfRecords> <records> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00322032</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/2306831 +5</dc:identifier> <dc:title>TEST</dc:title> <dc:creator>KAY RYAN</dc:creator> <dc:relation>Poetry, Vol. 176, No. 3</dc:relation> <dc:coverage>p. 126</dc:coverage> <dc:rights>Copyright 2000 Poetry Foundation</dc:rights> <dc:publisher>Poetry Foundation</dc:publisher> <dc:date>2000-06-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>1</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 0010096X</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/357303< +/dc:identifier> <dc:title>Test</dc:title> <dc:creator>Wm. Leonard</dc:creator> <dc:relation>College Composition and Communication, Vol +. 29, No. 2</dc:relation> <dc:coverage>p. 161</dc:coverage> <dc:rights>Copyright 1978 National Council of Teachers +of English</dc:rights> <dc:publisher>National Council of Teachers of English</ +dc:publisher> <dc:date>1978-05-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>2</recordPosition> </record> </records> </searchRetrieveResponse>";

i have to parse it and also need to fetch value of title and creator, etc.I wrote a script but not able to fetch.

my $x = new XML::LibXML(); my $data = $x->parse_string($xml); my $recordData = $data->findnodes('/records/record/recordData/'); foreach my $rec(@$recordData){ print STDERR "helloooooooooooooooooooooooooooooooo"; my $title = $rec->findnodes('title')->string_value(); print STDERR $title . "\n"; }

how do I fetch url in <identifier> tag instead of ISSN as they both have the same tag name

Plesae help me out. Thanks in Advance....


In reply to facing problem in parsing xml by Priti24

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.