commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allen,Eva" <all...@oclc.org>
Subject RE: [Digester] Can digester match an unknown element?
Date Thu, 27 Mar 2008 19:29:27 GMT
Thanks to both of you for your quick responses.  To Simon, unfortunately
the entity involved does not wish to be limited by the constraints
imposed by a schema, which is why we run into this situation in the
first place.

Both solutions sound good.  I'll get back to you with results as soon as
I can.

Thanks.

-----Original Message-----
From: simon.kitching@chello.at [mailto:simon.kitching@chello.at] 
Sent: Thursday, March 27, 2008 5:58 AM
To: Jakarta Commons Users List
Subject: Re: [Digester] Can digester match an unknown element?

Allen,Eva schrieb:
> We are working with an entity which sometimes adds new xml elements 
> without remembering to tell us about them.  We would like to be able 
> to log a warning whenever we encounter an element that we don't know
about.
>
> Is there any way to do this with digester? 
>
> Specifically, we have really simple xml files that in essence, look 
> like
>
> this: 
> <xmlrecord> 
>     <good>acceptedValue1< /good> 
>     <good>acceptedValue2</good> 
>     <bad>rejectedValue1< /bad> 
>         . 
>         . 
>         . 
> </xmlrecord>
>
> and the digester rules file looks like this: 
> <digester-rules> 
>     <pattern value="xmlrecord"> 
>         do some stuff 
>         <pattern value="good"> 
>             do more stuff 
>         </pattern> 
>         <pattern value="bad"> 
>             do even more stuff 
>         </pattern> 
>     </pattern>
> </digester-rules>
>
> All of a sudden one day, we got an "xmlrecord" with an "unworthy" 
> element (names have been changed here to protect the innocent).   We 
> would have liked to log a warning that we didn't know what to do with 
> an
>
> unworthy element, but I can find no way to tell digester how to parse 
> that.  I've tried patterns "xmlrecord/*" and "*/*" but neither one of 
> those works.  I've looked at the digester documentation including the 
> wiki page.  Everybody talks about generalized pattern matching but 
> nobody talks about unknown elements.  Is there any way to do this with

> digester?
>
>   

A pattern-matching approach will not work, because it will match nodes
that are *also* matched by other rules.

I don't believe there is any way to do this with Digester at the moment,
but it sounds like a very useful addition, and not too hard to do.
Simply having the Digester object invoke some kind of callback when zero
rules match a node should be fairly easy to add. If you can create a
patch for that, plus unit test, I'll happily apply it.

Alternately, you could create an xml schema for your input file, and set
up the xml parser to do validation. That will allow much more flexible
checking of the input than just "node with no matching rule".

Regards,
Simon




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message