Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

As I have posted before, I help maintain a set of Perl scripts which use XML::Twig to run validation checks on dictionary entries written in XML. The checks are looking for things that a DTD would not spot.

In Node XML::Twig prev_sibling I asked for help with a piece of code which decided whether a sense in the entry was to be considered rare or not.

Now I have a further problem relating to this issue: there is another piece of text which might mean that something labelled "rare" in an la element is actually not rare:
<la>rare</la> before the 20th century.
<la>rare</la> after the 18th century.
In both these cases, for checking purposes the sense or entry should be treated as "not rare"

The piece of code I posted in the previous question I have been able to modify to handle this as it is handling the parent element of the <la> element. This code is called at the sense level within the XML.

Howevere there is other fairly similar code to handle things for the entry as a whole:

sub la_obs_handler { my ($t,$elt) = @_; my $la = $elt->text; my $isNow = 0; if ( ($prev && $prev->text =~ m/[nN]ow $/) || $elt->parent->text =~ m/[nN]ow .* and rare/ || $elt->parent->text =~ m/rare after/ || $elt->parent->text =~ m/rare before/ ) { $isNow = 1; } if ( $la eq "rare" && ! $isNow ) { $is_entry_rare = 1; } }

This should set the variable $is_entry_rare to 1 if the <la> element being handled contains the text "rare" but not if it is also preceded by "Now" or "Now <something> and". This works. However it should also not set the varaibale to 1 if the la element is followed by sibling text saying "after ...." of "before ...." I have tried testing the parent node's text content as shown in my code but it does not seem to work - I think this is because XML::Twig has not accessed anything following the <la> element since it is handling that element.

Is there any way of getting at the text following the <la> element? I know I could do this by handling the parent element instead but I don't think that is an option with my legacy code. Are any other solutuions possible?

In reply to XML:: Twig - can you check for text following the element being handled? by mertserger

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2018-04-26 16:12 GMT
    Find Nodes?
      Voting Booth?