kjp
kjp

Reputation: 3116

When using commons-digester XML rules, how do I exclude some attributes of the XML that I dont need?

I am trying to use apache-commons-digester 3 to load an XML into an object. The problem I am facing is that some of the tags have attributes that I am not interested in. But if I use a <set-properties-rule> rule it tries to load all the attributes into the object properties and fails when it finds that some attributes do not have matching properties. How do I exclude these attributes? I am looking for something like <set-properties-rule exclude="/xmlns:xsi*"/>

Upvotes: 1

Views: 1407

Answers (2)

St&#233;phane Appercel
St&#233;phane Appercel

Reputation: 1507

The ignore element is not in the DTD embedded in the digester library, and this is causing some nasty exceptions at runtime. Another approach consists in using an alias without specifying the property value, as in the following example:

<set-properties-rule>
    <alias attr-name="whatever" />
    <alias attr-name="surname" prop-name="lastname" />
</set-properties-rule>

In the example above, the attribute "whatever" is ignored.

The documentation of the SetPropertiesRule class says:

If a property name is null or the attribute name has no matching property name, then this indicates that the attibute should be ignored.

Sorry for this late answer, but I've just had this problem in my project and found this solution. It works perfectly well for me (I'm using with digester3-3.2).

Upvotes: 0

Met
Met

Reputation: 3172

I think what you are looking for is the ignore rule. I think this was added on some 3.x version.

<set-properties-rule>   
    <ignore attr-name="whatever" />
    <alias attr-name="surname" prop-name="lastname" />
</set-properties-rule>

Upvotes: 1

Related Questions