Frequently Asked Questions

This document attempts to answer some of the more frequently asked questions regarding various aspects of Betwixt. These questions are typically asked over and over again on the mailing lists, as a courtesy to the developers, we ask that you read this document before posting to the mailing lists.

General

  1. What is Betwixt?
  2. Why is this called Betwixt?
  3. How does Betwixt compare to technologies like JAXB and Castor?

Writing Beans

  1. In what forms can Betwixt output the xml?
  2. Can BeanWriter produce xml that's easy (for a human ;) to read?
  3. How does Betwixt cope with beans which have cyclic reference graphs?
  4. How can I stop Betwixt generating ID attribute values for my beans?

Building Betwixt

  1. How do I build Betwixt?

General

What is Betwixt?
The Betwixt library provides an XML introspection mechanism for mapping beans to XML in a flexible way. Please see the Home page and Overview documents for more detail.
Why is this called Betwixt?
I grepped a dictionary for words containing B*T*X for Bean To XML. There's not many words around containing those 3 letters in order. Betwixt also seems a fitting name as its the stuff between (betwixt) Beans and XML.
How does Betwixt compare to technologies like JAXB and Castor?
Where JAXP and Castor are strong is when you have a well agreed schema (XML Schema for Castor or a DTD in the case of JAXB, last time I looked) and want to auto-generate beans for parsing and processing the XML.
Betwixt is strong is when you've already got the beans and just want a nice looking XML format to serialize/deserialize your beans. Indeed with Betwixt you can just write your beans and not even worry about XML schemas and providing you follow a simple bean naming convention (the use of getter, setter and adder methods) you'll get nice looking XML for free.
In JDK1.4 there is a long term bean serialization mechanism which you can use. However Betwixt generates cleaner looking XML which can be customized to your own look and feel. Long term bean serialization doesn't generate nice looking XML.

Writing Beans

In what forms can Betwixt output the xml?
At the moment, BeanWriter is the only way to output the xml. This writes the xml (as characters) to standard java io streams. Work will begin on a SAX-based writer (which will generate SAX events) very soon.
Can BeanWriter produce xml that's easy (for a human ;) to read?
Yes! Call
beanWriter.enablePrettyPrint();
(For those who are extra picky, how this is done can also be adjusted. See java docs for details.)
How does Betwixt cope with beans which have cyclic reference graphs?
The default behaviour is to use the ID -IDREF mechanism (described in the xml specification). Betwixt will automatically assign ID values to beans as it write out the graph. If it comes to a bean that it's written before, it will write an IDREF value matching the original.
How can I stop Betwixt generating ID attribute values for my beans?
This is controlled by a property on BeanWriter . Call
beanWriter.setWriteIDs(false);
and then Betwixt will no longer automatically add ID attributes. Once this property is set (to false), BeanWroter will throw a CyclicReferenceException when any cyclic references which are encountered in the bean graph.

Building Betwixt

How do I build Betwixt?
Betwixt uses Maven for its build system. So you should be able to build Betwixt just like any other Maven enabled project. Please see the Maven documentation for details.