I didn't have anything better to do on this balmy Saturday afternoon, so I coded up a solution that uses XML::Parser.
use strict; use warnings; use XML::Parser; my $p1; $p1 = new XML::Parser( Handlers => { Start => \&handle_start, End => \&handle_end, Proc => \&handle_proc }); my @stack; $p1->parse(\*DATA); if (@stack) { warn "stack not empty\n"; } sub handle_start { my ($parser, $element) = @_; print " " x scalar(@stack), "BEGIN $element\n"; push(@stack, $element); } sub handle_end { my ($parser, $element) = @_; my $top = pop(@stack); print " " x scalar(@stack), "END $element\n"; unless ($element eq $top) { warn "expected $element, found $top\n"; } } sub handle_proc { my ($parser, $target, $data) = @_; if ($target eq 'CLG.MDFO') { handle_start($parser, $target); } elsif ($target eq 'CLG.MDFC') { handle_end($parser, 'CLG.MDFO'); } } __END__ <?CLG.MDFO ID="O001001M004000" IDREF="C001001M004000" ACTION="REPLACED +" LEVEL="STRUCTURE" COMMAND="EXPLICIT" ACTIVE.DOC="306D0754" ACTIVE.L +OC="AR:1;PT:4" MOD.LEVEL="1" PASSIVE.LOC="AR:5"?> <ARTICLE IDENTIFIER="005"> <TI.ART>Article 5</TI.ART> <STI.ART>Recovery of costs</STI.ART> <?CLG.MDFO ID="O002001M003000" IDREF="C002001M003000" ACTION="REPLACED +" LEVEL="STRUCTURE" COMMAND="EXPLICIT" ACTIVE.DOC="308D0162" ACTIVE.L +OC="AR:1;PT:3" MOD.LEVEL="1" PASSIVE.LOC="AR:5;PA:1"?> <PARAG123 IDENTIFIER="005.001"> <NO.PARAG>1.</NO.PARAG> <ALINEA>All costs resulting from issuing the accompanying documents pu +rsuant to Article 2(2) shall be borne by the food business operator r +esponsible for the consignment or its representative.</ALINEA> </PARAG123> <?CLG.MDFC ID="C002001M003000" IDREF="O002001M003000"?> <PARAG IDENTIFIER="005.002"> <NO.PARAG>2.</NO.PARAG> <ALINEA>All costs related to official measures taken by the competent +authorities as regards non-compliant consignments shall be borne by t +he food business operator responsible for the consignment or its repr +esentative.</ALINEA> </PARAG> </ARTICLE> <?no_smark?> <?CLG.MDFC ID="C001001M004000" IDREF="O001001M004000"?>

In reply to Re: Not able to Matching nested item by pc88mxer
in thread Not able to Matching nested item by ngbabu

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.