commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Betwixt: BeanReader setup question
Date Wed, 09 Apr 2008 18:32:59 GMT

So I have an example working....

Given the input XML file (me.xml):
<?xml version='1.0' encoding='UTF-8' ?>
<me id="he3432h11-032">
    <a name="rock hard" />
    <b name="monkey" />
    <c name="scam tactics" />
public class MeElement {
	private String id;
	private String nameA;
	private String nameC;
  /* I have getters/setters defined for omitting them here */

<?xml version='1.0' encoding='UTF-8' ?>
<info primitiveTypes="element">
   <element name="me">
     <attribute name="id" property="id" />
     <element name="a">
       <attribute name="name" property="nameA" />
     <element name="c">
       <attribute name="name" property="nameC" />

Remember that the .betwixt file needs to be in the same directory that your
.java file is.  Betwixt will pick up both theses files since they're on the
classpath together.

I'll assume that you have JUnit setup (because we all know that testing is
important...even former .NET people like me).  So I have a subclass of 
with the following method defined:

public void testMeDocumentLoad() {
   try { // this assumes that 'me.xml' is sitting on the classpath
     InputStream xtnodes = getClass().getResourceAsStream("./me.xml");
     BeanReader beanReader = new BeanReader();
     MeElement root = (MeElement)beanReader.parse(xtnodes);
     // add further testing to ensure that the bean/pojo has been loaded as
   } catch (Exception e) {
     System.out.println("exception occured... lame");

Betwixt does have log4j capabilities (apparently).  I tried to 
configure it for
my unit test but I'm not getting any INFO output.  I'm not really too familiar
with log4j - so I can't really offer any help.  I just was able to 
confirm that
you should be able to get DEBUG/INFO/WARN information about Betwixt via log4j.

I hope that helps,


  * @author:  Andrew Lenards
  * @email:
  * @title:   Systems Programmer, Principal
  * @project: Tree of Life Web Project
  * @website:
  * @dept:    Dept. of Entomology
  * @school:  University of Arizona
  * @geo-loc: Tucson, AZ 85721

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

View raw message