commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [digester] XML Parsing problem
Date Thu, 13 Apr 2006 09:34:02 GMT
Hi Qaiser,

For the future, here are some recommendations:
 * Do not send a "user" type email to message to both dev
   and user lists. It annoys the very people you're asking
   for help.
 * Do not send the same email multiple times, for the
   same reason.

The original authors of the "xml rules" module have long since vanished,
so help is a little hard to get for that (you'd have better luck if you
were just using the plain Digester API).

I suggest enabling logging output for digester; it is quite helpful.
See the javadoc "package summary" for the org.apache.commons.digester
package for information on enabling logging output.

http://jakarta.apache.org/commons/digester/commons-digester-1.7/docs/api/org/apache/commons/digester/package-summary.html

Regards,

Simon

On Tue, 2006-04-11 at 15:31 -0400, Qaiser Mehmood wrote:

> I am using Commons Digester to parse one XML file to a Java Object and
> the code is not populating my Java Bean. The XML Files are 
> 
>  
> 
> Rules.xml :
> 
>  
> 
> <?xml version="1.0"?>
> 
>  
> 
> <digester-rules>
> 
>   
> 
>  <pattern value="messages/message">
> 
>             <object-create-rule
> classname="com.rhg.infrastructure.dao.bean.Message" />
> 
>             <set-next-rule methodname="add"
> paramtype="java.lang.Object"/>
> 
>             <set-properties-rule />
> 
>             <bean-property-setter-rule pattern="application_name"/>
> 
>             <bean-property-setter-rule pattern="createDate"/>
> 
>             <bean-property-setter-rule pattern="createdBy"/>
> 
>             <bean-property-setter-rule pattern="id"/>
> 
>             <bean-property-setter-rule pattern="index_page"/>
> 
>             <bean-property-setter-rule pattern="message_text"/>
> 
>             <bean-property-setter-rule pattern="priority"/>
> 
>             <bean-property-setter-rule pattern="signature"/>
> 
>             <bean-property-setter-rule pattern="user_id"/>
> 
>             
> 
>   </pattern>
> 
> </digester-rules>
> 
>  
> 
> Test.xml :
> 
>  
> 
> <?xml version="1.0" ?>  
> 
>  <messages>
> 
>   <message>
> 
>     <application_name>Find Doc</application_name>
> 
>     <createDate>2006-04-11 09:48:22.406</createDate>
> 
>     <createdBy>1</createdBy>
> 
>     <id>0</id>
> 
>     <index_page>index.jsp</index_page>
> 
>     <message_text>Error on Index.jsp</message_text>
> 
>     <priority>5</priority>
> 
>     <signature>Revolution Team</signature>
> 
>     <user_id>1</user_id>
> 
>   </message>
> 
>  </messages>
> 
>  
> 
> And the code :
> 
>  
> 
> List messagesList = new ArrayList( );
> 
> URL rules = getClass( ).getResource("/rules.xml");
> 
> Digester digester = DigesterLoader.createDigester(rules);
> 
> digester.push(messagesList);
> 
> InputStream input = getClass( ).getResourceAsStream("/test.xml");
> 
> Object root = digester.parse(input);
> 
> message = (Message) messagesList.get(0);
> 
>  
> 
>  System.out.println("message application name "+message);
> 
>  
> 
> There are elements in messageList , bu the fileds in message are null.
> So Field from the 2nd XML file are not populated. Any help. I will
> appreciate prompt response.
> 
>  
> 
> Qaiser Mehmood
> 
>  
> 


---------------------------------------------------------------------
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