From: Gavin_King/Cirrus%<CI...@ci...> - 2002-03-23 02:08:18
|
> Why was JDom chosen as the XML toolkit of choice? I > think using Dom4J or something else that supports > XPath would make life much easier in the mapping file. Actually to parse mapping files (DOCTYPE hibernate-mapping.dtd) I'm using vanilla JAXP. This was probably a mistake. JDOM is used to construct XML representation of persistent objects. Don't think XPATH would help us here. I've never used DOM4J. Is it better than JDOM in other ways? If I was redoing this from scratch I would take a close look at using JAXB or something similar for parsing the mapping file. > I am currently working on an XML mapping system where > I work (specific use) and am wondering what your plans > are for XML. Is it going to be the same interface as > your SQL databinding? I'm not sure if you realise, but XML generation is already implemented. It just isn't documented in the tutorial. Check the JavaDocs for a quick summary. Start out with SessionFactory.openDatabinder() Basically, when I got round to implementing this, I had a look around and discovered that the open source solutions for databinding had improved a whole lot and I didn't want to try and waste time doing what other people are doing better. I figured plenty of other projects are trying to let you arbitrarily map XML to objects and vice-versa. So I decided to do something real simple. 1. I didn't want to introduce yet another OO to XML mapping language. 2. I wanted XML generation for persistent classes to "just work". ie. you don't need to do any mapping at all most of the time. 3. I wanted it to be _possible_ to customize the generated XML either on a per-class or whole application basis. My solution was to use XSLT as the mapping language and provide a default stylesheet that does what you would probably want. You can customize the stylesheet to alter the mapping for individual classes, or for all classes at once. I kinda like this. So XML generation became a two-step process. 1. generate a "generic" XML representation that is amenable to manipulation by XSLT and includes as much information as you could possibly want. <object class="Foo" package="cirrus.hibernate.test"> <uid name="key" type ="string">52b16c9d:ecc0e74d:00ec:c0e7d476:0011</uid> <property name="foo" type="cirrus.hibernate.test.Foo" /> ..... </object> 2. use Xalan to process that XML with the (custom or default) stylesheet. <Foo id="N400005"> <key>52b16c9d:ecc0e74d:00ec:c0e7d476:0011</key> <foo/> ...... </Foo> There would be some extra problems in going backward from XML to Java but I didn't want to waste too much time on that problem if no-one was using hibernate for XML generation. (I guess I should start by documenting it, though.) |