Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2022-05-18 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (70 votes). Check out past polls.

    Notices?