For Coconut, the side software project I work on, I used to use the JAXB package from Sun. JAXB can parse schemas and generates classes that handle representing XML documents as a tree of objects.
It sounds good in theory, but I ran into two problems in using it:
- Schemas don’t seem to be very good at specifying really wacky rules. It can do it, but it gets very verbose. The main case I ran into was that I had a tree of elements defined, and depending on the value on an attribute near the root of the tree, the validity rules of the rest of the tree changed very slightly. e.g. a XML document representing “John Doe” may or may not have a street address element; however, if his street address is specified, then a sibling element for the postal code is mandatory.
- JAXB generates a set of classes. I then go on to use those classes in the rest of the application, by classes containing business logic. However, those classes are sensitive to the schema. The schema is not an international standard – it’s just my current expectations on a custom message format. Thus, it’s subject to churn, which causes the object model to churn, which causes a lot of breakage. This is worsened by the previous point, that seemingly small rule adjustments cause great increases in schema verbosity.
I’m not particularly well-versed in schemas, and I picked up JAXB based on a high level description from a coworker; it’s possible I’m misunderstanding something. However, in hindsight I should have known better, as I’ve worked on another project that used an XML schema (with a standards body) to generate a core object model – that one didn’t turn out well either.