You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Arjun Ram <ar...@myway.com> on 2003/07/31 22:34:59 UTC

Digester Newbie question

Hi,

Im trying to load a simple XML file. Here is a sample

<?xml version="1.0"?>
<importtask>
	<database>
		<driver>com.sybase.jdbc2.jdbc.SybDriver</driver>
		<url>jdbc:sybase:Tds:169.69.273.203:10587</url>
		<username>sdssdbo</username>
		<password>sdssdbo</password>
	</database>
	<importsource>
		<tablename>SVHCL</tablename>
	</importsource>
	<importsource>
		<tablename>SVHCL</tablename>
	</importsource>
</importtask>

corresponding code:

digester = new Digester();
digester.addObjectCreate("importtask",
"com.dx.ops.mv.InsertDB");
digester.addCallMethod(
			"importtask/database/driver",
					"setDriver",
					0);

digester.addCallMethod("importtask/database/url", "setUrl", 0);
digester.addCallMethod(
			"importtask/database/username",
					"setUsername",
					0);
digester.addCallMethod(
 		"importtask/database/password",
					"setPasswd",
					0);

digester.addSetNext("importtask/importsource", "addimporttask");

digester.addObjectCreate(
			"importtask/importsource/",
"com.dx.ops.mv.ImportSourceBean");

				digester.addSetProperties("importtask/importsource");
digester.addBeanPropertySetter(
			"importtask/importsource/tablename",
			"tablename");
digester.parse("config.xml");

But addBeanPropertySetter for tablename seems to pick up InsertDB class not the ImportSourceBean. Am I making a simple mistake some place?

Thanks in advance
Arjun

P.S: its sad to see not many samples for digester

_______________________________________________
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com

Re: Digester Newbie question

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Thursday, July 31, 2003, at 09:34 PM, Arjun Ram wrote:

> Hi,
>
> Im trying to load a simple XML file. Here is a sample
>
> <?xml version="1.0"?>
> <importtask>
> 	<database>
> 		<driver>com.sybase.jdbc2.jdbc.SybDriver</driver>
> 		<url>jdbc:sybase:Tds:169.69.273.203:10587</url>
> 		<username>sdssdbo</username>
> 		<password>sdssdbo</password>
> 	</database>
> 	<importsource>
> 		<tablename>SVHCL</tablename>
> 	</importsource>
> 	<importsource>
> 		<tablename>SVHCL</tablename>
> 	</importsource>
> </importtask>
>
> corresponding code:
>
> digester = new Digester();
> digester.addObjectCreate("importtask",
> "com.dx.ops.mv.InsertDB");
> digester.addCallMethod(
> 			"importtask/database/driver",
> 					"setDriver",
> 					0);
>
> digester.addCallMethod("importtask/database/url", "setUrl", 0);
> digester.addCallMethod(
> 			"importtask/database/username",
> 					"setUsername",
> 					0);
> digester.addCallMethod(
>  		"importtask/database/password",
> 					"setPasswd",
> 					0);
>
> digester.addSetNext("importtask/importsource", "addimporttask");
>
> digester.addObjectCreate(
> 			"importtask/importsource/",
> "com.dx.ops.mv.ImportSourceBean");
>
> 				digester.addSetProperties("importtask/importsource");
> digester.addBeanPropertySetter(
> 			"importtask/importsource/tablename",
> 			"tablename");
> digester.parse("config.xml");
>
> But addBeanPropertySetter for tablename seems to pick up InsertDB class 
> not the ImportSourceBean. Am I making a simple mistake some place?

the tricky thing with digester is that the order of the rules is important.

i think that one problem you have is that the SetNextRule executes before 
the ObjectCreateRule when 'importtask/importsource' is matched. i think 
that the SetNextRule should be placed after the ObjectCreateRule.

another problem that i think you might have is with

digester.addObjectCreate("importtask/importsource/")

i suspect (but haven't had the chance to prove right now) that this will 
fail to match. try changing to

digester.addObjectCreate("importtask/importsource")

hope this helps

> P.S: its sad to see not many samples for digester

it certainly is :)

if you find this email useful then you'd consider spending a few minutes 
creating and contributing a documentation patch with one (or better still 
more than one) simple sample in.

- robert