bharatbsharma has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: parsing of xml with mutiple tags
by toolic (Bishop) on Jun 11, 2010 at 12:29 UTC
    Welcome to the Monastery. Please read Writeup Formatting Tips, then update your post using code tags for your code and XML data.

    Use XML::Twig:

    use strict; use warnings; use XML::Twig; my $xmlStr = <<XML; <?xml version="1.0" encoding="utf-8"?> <result> <suites> <suite> <name>(Multiple_Sub_disp.xml)</name> <duration>2.0</duration> <cases> <case> <duration>2.0</duration> <className>Regression.CR0097956</className> <testName>CR0097956_Multiple_Sub_disp</testName> <skipped>false</skipped> <failedSince>10</failedSince> </case> </cases> </suite> <suite> <name>(Multiple_Sub_mod.xml)</name> <duration>12.0</duration> <cases> <case> <duration>12.0</duration> <className>Regression.CR001000</className> <testName>CR0097956_Multiple_Sub_mod</testName> <skipped>false</skipped> <failedSince>20</failedSince> </case> </cases> </suite> <suite> <name>(Single_Sub_create.xml)</name> <duration>12.0</duration> <cases> <case> <duration>12.0</duration> <className>Regression.CR002000</className> <testName>CR0097956_Single_Sub_create</testName> <skipped>false</skipped> <failedSince>10</failedSince> </case> </cases> </suite> </suites> <duration>34082.0</duration> </result> XML my $twig= XML::Twig->new( twig_handlers => { className => sub { print $_->text(), "\n" } } ); $twig->parse($xmlStr); __END__ Regression.CR0097956 Regression.CR001000 Regression.CR002000

    I used XML::Tidy to neaten up your XML data.

Re: parsing of xml with mutiple tags
by jethro (Monsignor) on Jun 11, 2010 at 11:51 UTC
    Please edit your node and put <code> </code> tags around any code. This is the most important hint of many below the edit window on how to format a question. As it is now, your question is practically unreadable.
Re: parsing of xml with mutiple tags
by Kanishka.black0 (Scribe) on Jun 12, 2010 at 22:03 UTC

    you need Xpath modules to get the exact value of the Node ....try XML::Xpath

    i tried to use XML::LibXML but ran into some problems .. please post the code Cleanly .....

    i just pasted the xml into a hello.xml ....
    use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file('hello.xml'); foreach my $book ($doc->findnodes('/result/suites/suite/cases/case') +) { my($title) = $book->findnodes('./className'); print $title->to_literal, "\n" }
    i think this is what you are looking for ...