You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by ts...@InPhact.com on 2003/03/20 18:54:21 UTC

[DIGESTER] Pattern Matching

Hello,  I am trying to build a rules file and I want to accomplish the
following.

Match an element that is nested only under certain parent elements. Is there
support for "or" type matching, .e.g. "(a|b|c)/e"?

I have an element that may be nested recursively.  I mean it can be
contained within itself or within one other type of element.  I tried to
match like this...

<pattern value="a/b">
	...
	<pattern value="*/c">

where the xml file could be

<a>
  <b>
    <c>
      <c>

But it did not match.

Any ideas or suggestions would be greatly appreciated.

Thanks,

Ted Slusser
InPHact  - The Radiology Solutions Company
5141 Virginia Way
Brentwood, TN 37027
(615) 843-2918


Re: [DIGESTER] Pattern Matching

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Thursday, March 20, 2003, at 05:54 PM, tslusser@InPhact.com wrote:

> Hello,  I am trying to build a rules file and I want to accomplish the
> following.
>
> Match an element that is nested only under certain parent elements. Is 
> there
> support for "or" type matching, .e.g. "(a|b|c)/e"?

yes and no :)

the rules implementations which ship with digester (RulesBase and 
ExtendedBaseRules) don't support this kind of logic. if you want, though, 
you can create a new Rules implementation which does and then use digester.
setRules.

i'm not sure that i'd be in favour of adding logic to ExtendedBaseRules 
but if there is demand and developers willing to lend a hand, i'd be glad 
to help with an effort to develop a Rules implementation with some simple 
logic. another possibility might be to use ORO to develop a regex-based 
Rules implementation.

at the expense of more verbose code you can achieve the same effect 
programmatically. you create the Rule implementation first and then add it 
at each of the patterns in the OR logic combination.

> I have an element that may be nested recursively.  I mean it can be
> contained within itself or within one other type of element.  I tried to
> match like this...
>
> <pattern value="a/b">
> 	...
> 	<pattern value="*/c">
>
> where the xml file could be
>
> <a>
>   <b>
>     <c>
>       <c>
>
> But it did not match.

again, this isn't really supported by the Rules implementations which ship 
with digester. a custom Rules implementation seems like a better bet.

i had been thinking about a new Rules implementation that might allow this 
kind of thing to be specified. the idea is that it'd delegate sub trees to 
other Rules implementation. i'm not really sure how this would be 
specified using the xml-rules, though. any ideas about how to do this 
would be appreciated.

- robert