You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Lance Semmens <la...@essential.com.au> on 2005/01/14 06:03:45 UTC
[digester] Unhandled element and attributes
Do any rules exist that will execute if an unexpected element or attribute
is encountered in an XML file.
For the following xml
<tag-a/>
<tag-b/>
<tag-c/>
And the following code
Digester dig = new Digester();
dig.addObjectCreate("*/tag-a", ATag.class);
dig.addCallMethod("*/tag-b", "doBTag");
dig.parse(...);
I'd like a way of handling all the patterns that I have not attached rules
to.
In my example, I have not attached a rule to <tag-c/> so I'd like to produce
a warning in this case.
Any suggestions?
Thanks,
Lance.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [digester] Unhandled element and attributes
Posted by Bill Keese <bi...@tech.beacon-it.co.jp>.
>Do any rules exist that will execute if an unexpected element or attribute
>is encountered in an XML file.
>
>
You are looking for something other than the standard schema validation,
right? Here's what I did:
digester.setRules(new ExtendedBaseRules());
// add all your normal rules here
digester.addRule("*/?", new Rule() {
public void begin(java.lang.String namespace,
java.lang.String name, org.xml.sax.Attributes attributes)
throws Exception{
throw new Exception("Unknown tag " + name);
}
});
This is like the "default" tag in a "case" statement, that only fires if
none of the other conditions match.
Bill
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org