I am not using Castor, as it has a problem with attributes in different
elements but with same name ("tc" in my case) having different allowable
values.

When I generate my code, I end up with classes that can be populated from
XML via dom4j, no castor required.  Load up time for my classes is less than
Castor, and like Castor (and unlike JASB), my objects are "pure", in that
they have no knowledge of XML.  A separate class is used to marshal and
unmarshal them.  

I successfully retargeted my code from building one DTD to another in a few
minutes, so that saved a bunch of time.  Now at 154 classes generated.

I don't want to knock Castor.  I think it'll do great when it gets to 1.0,
but it's got some issues now, like only partial support for Collections
(there was an email about it a few days ago in dev list, to use them you
need a mapping file.)  Also, the tc problem noted above.  In any case, there
are a few things in Castor I am not sure I like:

* For performance reasons, I don't want to use introspection, but castor
requires <Class>Description.java files for each file if you don't do
introspection.  I like having all of that in one file, as my class number is
getting big already, and Castor generated 350+ classes for me...
* Load time.  Awful long at 29s
* The handling of choice items in DTD or Schema.  IN Castor, if you have
Element (a | b | c)..., it creates Element class with a single ArrayList
named Choice.  I prefer having setters for a,b,c, and putting some more
checking logic in the setters to replace the old set.  I see the logic in
the Castor idea, but I'm not sold on it at this point.
* I wanted to have some more control over how my beans were created.  The
DTD I use can have some shortcuts (<element tc="5">Descrioption of
5</element>.  In this case, you can skip holding the description, since 5
can be looked up at any time.)

I think the big items are load time, and number of classes...  Besides, I
learned quite a bit about dom, dom4j, sax, and creating classes with this
project, and it saved me typing over 60,000 lines of code.  I wish the DTD
parser JAR I am using was a bit less restrictive on how to use it, but I
managed to work around any issues.

Now, that said, the dom4j code it spits out isn't grandiose.  Basically, I
walk the tree of nodes, and creates classes, set fields, or throw exceptions
as need be.  Pretty boring code, but it is fast (100ms for huge XML after
initial load of classes) and easy to understand.

As for your idea, if someone can springboard from my code to an even better
idea, or pitch a concrete idea to me, I'll try to spit out the code, but I
am a XML neophyte at this point.  Namespaces scare me....

And yes, I am sold on dom4j.  I have switched all my developers over to it,
as it is much cleaner code than DOM, and XPath is a great addition.

Jim





Jim Brain, [EMAIL PROTECTED]
"Researching tomorrow's decisions today."
(319) 369-2070 (work)
SYSTEMS ARCHITECT, INDIVIDUAL ITS, LIFE INVESTORS INSURANCE COMPANY OF
AMERICA

 -----Original Message-----
From:   James Strachan [mailto:[EMAIL PROTECTED]] 
Sent:   Tuesday, November 20, 2001 6:18 AM
To:     Brain, Jim
Cc:     [EMAIL PROTECTED]
Subject:        Re: [dom4j-user] SAX vs DOM4J

Hi Jim.

This section sounds very interesting...

> So, I finished writing my classes by hand.  Used dtdparser to grab all the
> entities, and spit out class files for them.

Are these Castor classes you're generating or dom4j classes? I've often
wondered about code generating specific Element implementations for dom4j
that are schema aware and so can store their attributes and child elements
in a more efficient representation...


> Also had it spit out XMLWriter
> and XMLREader classes that marshal and unmarshal using dom4j.  XML spit
out
> 118 distinct classes.

I'm not sure I understand this bit. Are you going from Castor classes to
dom4j here?

James
----- Original Message -----
From: "Brain, Jim" <[EMAIL PROTECTED]>
To: "'James Strachan'" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, November 19, 2001 7:54 PM
Subject: RE: [dom4j-user] SAX vs DOM4J


> Here's some more information, for the folks looking into object<->XML.
>
> I reran my Castor test, and James, you were right.  The first invocation
> takes 29seconds, but after that 200ms.
>
> Currently, castor seems to have a problem with:
>
> <Element1 tc="2"/>
> <Element2 tc="1"/>
>
> If the tc attributed are separates lists of allowable numbers.  Castor
wants
> all of them to be the same, as I see it.
>
> Tried JAXB, but the JXS mapping file I created chokes the jxc compiler.
>
> So, I finished writing my classes by hand.  Used dtdparser to grab all the
> entities, and spit out class files for them.  Also had it spit out
XMLWriter
> and XMLREader classes that marshal and unmarshal using dom4j.  XML spit
out
> 118 distinct classes.
>
> First unmarshal: 2.5 s for first load, 100-300 ms after.
> First marshal: 600ms first time, 20-100 ms after.
>
> So, dom4j looks pretty good from a performance point of view.
>
> Jim
>
> Jim Brain, [EMAIL PROTECTED]
> "Researching tomorrow's decisions today."
> (319) 369-2070 (work)
> SYSTEMS ARCHITECT, INDIVIDUAL ITS, LIFE INVESTORS INSURANCE COMPANY OF
> AMERICA
>
>  -----Original Message-----
> From: James Strachan [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 13, 2001 1:45 AM
> To: Brain, Jim
> Cc: [EMAIL PROTECTED]
> Subject: Re: [dom4j-user] SAX vs DOM4J
>
> I agree with Dane, its sounding like just using your own custom objects
and
> SAX might be better. Maybe something like JAXB or Castor might help you do
> the binding of XML -> your beans.
>
> You could consider using Jaxen (http://jaxen.org) and writing your own
> custom Navigator to implement XPath on top of your custom beans.
>
> James
> ----- Original Message -----
> From: "Brain, Jim" <[EMAIL PROTECTED]>
> To: "'Dane Foster'" <[EMAIL PROTECTED]>; "Brain, Jim"
> <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Monday, November 12, 2001 9:01 PM
> Subject: RE: [dom4j-user] SAX vs DOM4J
>
>
> > Well, here is what my code is doing:
> >
> > * I have to parse the entire document, so I know lazy parsing won't
help.
> > * I am simply trying to get the document into a set of custom objects I
> > wrote (<app><book><chapter>... int App().Book().Chapter();)
> > * I like the Dom4J way at present, but all of my classes have this big
> chunk
> > of code in them:
> >
> >     void parse(Element element) throws OLifEException {
> >         String name;
> >         Node node;
> >
> >         for ( int i = 0, size = element.nodeCount(); i < size; i++ ) {
> >             node = element.node(i);
> >             if ( node instanceof Element ) {
> >                 name=node.getName();
> >                 System.out.println("-->" + name);
> >                 if(name.equals("HoldingKey")) {
> >                     //setCreationDate(node.getText().trim());
> >                 } else if(name.equals("AccountDesignation")) {
> >                     //setCreationTime(node.getText().trim());
> >                 } else if(name.equals("HoldingTypeCode")) {
> >
> >
>
setHoldingTypeCode(OLifE.parseInt(((Element)node).attributeValue("tc").trim(
> > ),"HoldingTypeCode not a number"));
> > .
> > .
> > .
> > Where the loop is the same, but the names differ.  I was trying to come
up
> > with HashMap type interface, but each element requires something
different
> > be done.  Some require there be 1 element, some are 0+, some are simple
> > sets, and some are objects that need to be created.
> >
> > I thought about:
> >
> > HashMap.add("AccountDesignation",new
> JimAction("set","AccountDesignation"));
> > or something to that effect.  Where JimAction is a container that can
> either
> > call a setter, call an Add with the element as the
> >
> > And then JimAction would be the item that handles the chore, but that
> seems
> > like a lot of JimActions for the code, and would tend to slow it down, I
> > think.
> >
> > Jim
> >
> >
> > Jim Brain, [EMAIL PROTECTED]
> > "Researching tomorrow's decisions today."
> > (319) 369-2070 (work)
> > SYSTEMS ARCHITECT, INDIVIDUAL ITS, LIFE INVESTORS INSURANCE COMPANY OF
> > AMERICA
> >
> >  -----Original Message-----
> > From: Dane Foster [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, November 12, 2001 2:57 PM
> > To: Brain, Jim
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: [dom4j-user] SAX vs DOM4J
> >
> > That totaly depends on what your code is doing.  Here is my personal
rule
> of
> > thumb.  If I don't need random access to the XML or if memory use is
> > prohibitive use SAX, for everything else use dom4j.
> >
> > Dane Foster
> > Equity Technology Group, Inc
> > http://www.equitytg.com.
> > 954.360.9800
> > ----- Original Message -----
> > From: "Brain, Jim" <[EMAIL PROTECTED]>
> > To: "DOM4J Mailing List (E-mail)" <[EMAIL PROTECTED]>
> > Sent: Monday, November 12, 2001 3:32 PM
> > Subject: [dom4j-user] SAX vs DOM4J
> >
> >
> > Has anyone done any benchmarking of SAX (Xerces or Aelfred) versus
DOM4J?
> I
> > know DOM is slower, but I like the ease of DOM4J.  Is rewriting my code
> (for
> > performance) into SAX going to save me all that much?
> >
> > Jim
> >
> >
> > Jim Brain, [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > "Researching tomorrow's decisions today."
> > (319) 369-2070 (work)
> > Systems Architect, Individual ITS, Life Investors Insurance Company of
> > America
> >
> >
> > _______________________________________________
> > dom4j-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
> >
> >
> > _______________________________________________
> > dom4j-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
> >
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to