|
|
|
Sponsored Link •
|
|
Advertisement
|
Bill Venners: That subclass hierarchy reminds me of JAXB, where
classes map to the concepts represented in the data, not just to XML
concepts. For example, classes that represent description or
link elements in RSS, not just Element and
Attribute.
Elliotte Rusty Harold: I'm not up on the latest version of JAXB. I've skimmed through the specification and looked at it a little bit. I think the big difference with JAXB is that when you unmarshal, in their terminology, the XML document into their hierarchy, you really throw away a lot of the XML. You've lost a lot of things. And then that has to be marshaled back out into the XML if that's what you want. XOM would never lose track of the XML.
The other practical difference is that in XOM you would have to write your own
class libraries and hierarchies by hand. You would not have it built directly for
you by a schema compiler as in JAXB. So you'd have to write a
TableElement class, a BodyElement class, a
DivElement class, and so forth. So it would be a lot more work.
But if you're doing it for something like XHTML, it might be a product that's
shared across multiple groups and multiple developers, so the cost might be
spread.
Bill Venners: What I was imagining, though, was that
something like a schema compiler could generate subclasses of XOM's
Element class.
Elliotte Rusty Harold: That's a very interesting idea. I hadn't thought of that.
Bill Venners: I prefer parsing XML documents into objects that conceptually represent a schema's data model, because the code is more explicit. But that approach only makes sense if a schema exists and you can require that all documents strictly adhere to that schema. It isn't appropriate in all situations.
Elliotte Rusty Harold: Right, but if you had a schema, or could write a schema, it might be easier to write the schema than to write the individual classes. Even if it's not a W3C XML schema language schema, even if it is just an XML document that describes the classes you're going to need. Hell you could even write the compiler in XSLT if you wrote the schema in XML. It's a very interesting idea. I hadn't thought of it. It would take some work, but it might save a lot more work on the other end.
|
Sponsored Links
|