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

fellow monks,

Is there any module available to do XML Search ? to be more specific about my requirement, it follows like this :-

* If I know what element name to search from XML file, If I pass this Element name to this XML file, I would like to get the output as:-

Level1->Level2->Level3-><Element_name> Level1->Level2-><Element_name>
by using some of XML<modules> I have to write a code in such a way that create a datastructre and search the element name from this data structre will satisfy my requirement.

But, I am curios to know, any of you have used a perl module will do a XML search ? If so Please let me know.

I have used XMLSpy. but XMLspy is not a free software. that is the reason I am interested in knowing about perl module which will do a search in XML file.

Replies are listed 'Best First'.
Re: XML search module
by davorg (Chancellor) on Jan 15, 2007 at 09:47 UTC

    As has already been pointed out, you probably want to run XPath queries against your XML document. Both XML::XPath and XML::LibXML are good for processing XPath queries.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: XML search module
by ikegami (Patriarch) on Jan 15, 2007 at 06:26 UTC
    Sounds like you want to perform an XPath query (for "//Element_name"). There should be a module that executes XPath queries on an XML doc, and you should be able to get the parents of the objects returned.
Re: XML search module
by ftumsh (Scribe) on Jan 15, 2007 at 12:06 UTC
    XML::Twig comes with an xml_grep script ready to use.
Re: XML search module
by Jenda (Abbot) on Feb 19, 2007 at 17:23 UTC
    use XML::Rules; my $parser = XML::Rules->new( rules => [ '_default' => '', 'the_tag' => sub { my ($tag, $attr, $context) = @_; print join('->', @{$context}), "-><$tag>\n"; } ] ); $parser->parsefile( $filename);