I am setting up Digester to parse XML in this format:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<contents>
<Content id='585' type='DocumentTypeA' DateModified='07/19/2005'
Action='Add/Modify'>
<title>My Book</title>
<publisher>My Publisher</publisher>
</Content>
<contents>
The rules file I have is this:
<?xml version="1.0"?>
<digester-rules>
<pattern value="contents">
<object-create-rule classname="java.util.HashSet" />
<pattern value="Content">
<object-create-rule classname="com.myclasses.Document" />
<set-properties-rule>
<alias attr-name="id" prop-name="contentID" />
<alias attr-name="type">
<object-create-rule classname="com.myclasses.DocumentType">
<set-properties-rule>
<alias attr-name="type" prop-name="doctypeNm" />
</set-properties-rule>
</alias>
</set-properties-rule>
<bean-property-setter-rule pattern="title" propertyname="title" />
<bean-property-setter-rule pattern="publisher"
propertyname="publisher" />
<set-next-rule methodname="add" />
</pattern>
</pattern>
</digester-rules>
My problem is that I use Java classes generated by a tool that scans the
database. The com.myclasses.Document class does not have a "type"
property. Instead, it has a "doctypeid" property. I need to
instantiate a com.myclasses.DocumentType object, set its "doctypeNm"
property to the "type" attribute (eg. "DocumentTypeA"), then use it to
retrieve the value which which I can set the Document.doctypeid
property.
I thought of doing an object-create-rule on a HashMap class and using
that to store attributes, then setting the Document properties out of
the HashMap object, but that seems like a clumsy workaround.
Any ideas?
Thanks,
Paolo Valladolid
Software Developer
DFI International