commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: how to load xml during parse
Date Fri, 30 Sep 2005 23:59:59 GMT
On Thu, 2005-09-29 at 13:47 -0400, Russell Simpkins wrote:
> Hi,
> I'm having slight difficulty determining how to use digester to do more 
> advanced hidrating of my beans. I have an xml file like this
> <?xml version="1.0" encoding="UTF-8"?>
> <Site>
>         <siteId external="false" id="true" type="long" 
> maxlength="12"><![CDATA[1]]></siteId>
>         <title external="false" id="false" type="java.lang.String" 
> maxlength="100"><![CDATA[]]></title>
>         <Servers>
>                 <Server row="0" id="3" type="media" 
> external="true">/Server/3/Server.3.xml</Server>
>                 <Server row="1" id="4" type="media" 
> external="true">/Server/4/Server.4.xml</Server>
>                 <Server row="2" id="5" type="media" 
> external="true">/Server/5/Server.5.xml</Server>
>         </Servers>
> </Site>
> My java bean has an ArrayList named servers with get/set/add methods. What I 
> wanted to do was hydrate each Server object with the data in 
> /Server/5/Server.5.xml for instance, based on what is in 
> Site/Servers/Server. I can keep my XML documents smaller if I source the 
> data rather then have all of the the data in the <Server> XML document.
> I was hoping to do this with Digester rules:
> <?xml version="1.0"?>
> <digester-rules>
>    <object-create-rule pattern="Site" classname="com.fg.fgcms.Site" />
>    <bean-property-setter-rule pattern="Site/siteId" propertyname="siteId" />
>    <bean-property-setter-rule pattern="Site/title" propertyname="title" />
>    <pattern value="Site/Servers/Server">
>       <object-create-rule classname="com.fg.fgcms.Server" />
>       <set-next-rule methodname="addServer" />
>    </pattern>
> </digester-rules>
> Using XPATH one would simply call the document() function to get at the 
> nested XML data. I am not sure how I can do this with digester or with the 
> digester rules option.
> Can you offer any direction or help? It would be greatly appreciated.

I think you could do this with a FactoryCreateRule. Write a custom
ObjectCreationFactory subclass which creates a Digester instance, grabs
the filename from the xml attribute, processes the specified xml file,
then returns the Server object created by that sub-parse.

You would need to move the filename into an xml attribute, though,
rather than the body of the xml statement.

I don't use xmlrules myself, but believe you can reference your
ObjectCreationFactory subclass something like this:
  <factory-create-rule classname="my.factory.class"/>



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message