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

Hi , Is there any way to remove a <Resource> element in tomcat context.xml file using XML::Simple. Thanks In advance for all the suggestions
  • Comment on Tomcat context.xml parsing using XML::SImple

Replies are listed 'Best First'.
Re: Tomcat context.xml parsing using XML::SImple
by tobyink (Canon) on Nov 21, 2012 at 10:28 UTC

    For any XML work where any of the following is true, XML::Simple is not your friend:

    • The order of elements is important.
    • The distinction between an element and an attribute is important.
    • You want to preserve comments.
    • You want to preserve whitespace.

    Use something like XML::LibXML instead.

    TL;DR: No.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Is there any good option to parse the tomcat context.xml files using perl .

        Use something like XML::LibXML instead.

        or even XSH2

Re: Tomcat context.xml parsing using XML::SImple
by Anonymous Monk on Nov 21, 2012 at 10:13 UTC
    No.
Re: Tomcat context.xml parsing using XML::SImple
by Jenda (Abbot) on Nov 22, 2012 at 15:26 UTC
    use XML::Rules; my $parser = XML::Rules->new( style => 'filter', rules => { Resource => sub {}, } ); $parser->filter(\*DATA); __DATA__ <root> <b>dgfdg</b> <Resource>delete</Resource> <c>ffgdfg<Resource>ddd</Resource>ddddd</c> </root>

    See the docs if you want to filter a file and not a filehandle and write the result elsewhere than STDOUT.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.