in reply to Re: Twig / Simple / xmlgrep --help
in thread Twig / Simple / xmlgrep --help

Thanks alot for the suggestion. Actually I have so many XML files in a directory, and I cannt use element name(title) in the code. I want my script to be generic.
--
Best Regards,
Cherry

Replies are listed 'Best First'.
Re^3: Twig / Simple / xmlgrep --help
by Jenda (Abbot) on Aug 16, 2007 at 08:27 UTC

    Then build the ruleset in the script, something like:

    use XML::Rules; @ARGV == 5 or die "Usage: BookStore3.pl roottag datatag idtag fitertag + filtervalue\n"; my ( $roottag, $datatag, $idtag, $fitertag, $filtervalue) = @ARGV; my $parser = XML::Rules->new( rules => [ _default => 'content', $datatag => sub { return unless $_[1]->{$fitertag} eq $_[4]->{parameters}; my $id = delete $_[1]->{$idtag}; delete $_[1]->{'_content'}; return $id => $_[1] }, $roottag => 'pass no content', ] ); my $data = $parser->parse(\*DATA, $filtervalue); use Data::Dumper; print Dumper( $data); __DATA__ <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore>
    and called as
    BookStore3.pl bookstore book title category CHILDREN

      Got your point sir..and lemme thanku coz this is getting easier for me a lil bit!!

      But at the CmdLine it should have been

      root@localhost ~# perl BookStore3.pl CHILDREN
      In response our script should take the 'title' in that particular 'category' for looking up in the another text file and output (at STDOUT) the entire matched/grepped entry.

      Is this possible with XML::Rules alone?
      --
      Best Regards,

      Cherry

        As we have not seen the other XMLs and plaintext files we can't know what can the script assume, what has to be found out from the text file and what has to be passed to the script as parameters. XML::Rules will definitely not help you parsing the text file :)

        I think you should have enough info to at least start with the task so please do and if you get stuck, come back showing what you have and explaining what's the problem.