commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Russell Simpkins" <russellsimpk...@hotmail.com>
Subject how to load xml during parse
Date Thu, 29 Sep 2005 17:47:33 GMT
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[www.mysite.com]]></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.

Thanks,

Russ



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message