commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francis.LeMonn...@genedata.com
Subject Re: [Digester] - how to Parse Tag attributes and tag content with addObjectCreate and CallMethod...
Date Wed, 14 Apr 2004 11:44:10 GMT
Thanks for the feedback.

Unfortunately, there is not a lot I can do about the XML, which is from a public site.

I have solved the problem, but not quite with the mechanisms you suggest.

For the XML:
<Root> 
  <subSection> 
    <id>7</id>	 
      <Item Name="forProperty" Type="String">This is the 
Content</Item>  
      <Item Name="forAnotherProperty" Type="String">More 
Content</Item>  
  </subSection> 
</Root> 

I used this:

	digester.addObjectCreate("root", root.class);
	digester.addObjectCreate("root/subsection",subsection.class);
	digester.addBeanPropertySetter("root/subsection/Id", "id");
	digester.addObjectCreate("root/subsection/Item", Item.class); 
	digester.addSetProperties("root/subsection/Item", "Name", "name");
	digester.addSetProperties("root/subsection/Item", "Type", "type");
	digester.addSetNext("root/subsection/Item", "addItem" );
	digester.addCallMethod("root/subsection/Item", "addItemValue", 0); 
	digester.addSetNext("root/subsection", "addSubsection");

which seems to do the job of parsing, so that I have a root of subsections, each 
subsection containing items; each item has a list of 'properties' [name] with values 
corresponding to the tag 'content'.

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