This worked like a charm with xmlrules. All I had to do what do what I normally do and add those three lines of code (and create the LogUnknownElementRule, of course).
Thanks! -----Original Message----- From: Christian T Trimble [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2008 12:05 PM To: Jakarta Commons Users List Subject: Re: [Digester] Can digester match an unknown element? On Mar 27, 2008, at 2:29 AM, Allen,Eva wrote: > 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? > > > -- > Eva Allen > Consulting Software Engineer, OCLC, Inc. > 6565 Kilgour Pl., Dublin, OH 43017 > 614.764.6009 | [EMAIL PROTECTED] > Views contained herein are my own; they do not necessarily reflect > those > > of my employer > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > Eva, I am not sure how to do this with the xml based rules configuration, but you can create a default rule using the digester directly. To do this, you need to replace the Rules instance on your digester with a WithDefaultRulesWrapper and set the default rule to do your logging. Something like: Digester digester = new Digester(); // Configure your rules. ... WithDefaultRulesWrapper defaultRules = new WithDefaultRulesWrapper(digester.getRules()); defaultRules.add(new LogUnknownElementRule()); digester.setRules(defaultRules); Now, the LogUnknownElementRule will be called when an element does not match any of the rules in your rules configuration. --Christian Trimble --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
