Well, here's what I did last night: I reorged the code, so the objects are not aware of XML at all.
Ala Castor, I wrote a Marshaller.marshal() and Unmarshaller... objects. Inside those objects, I wrote the code to XMLize and De-XMLize the objects... in dom4j... My theory: I know dom4j, and I am interested in functionality at this point. If I need to SAX later, I can simply rewrite the Marshall and unmarshal objects to be SAX. The objects don't care. Good for me getting finished. Also, the best way to do the SAX implementation is to build a stack and drop inner classes that override DefaultHandler (or some extension of it) to check for and handle the element (some of the element names at different levels conflict, so you need to know where you are in the XML file to make sure you set the right var. By the time you create all these inner classes and such, the number of classes is getting somewhat close to the number of Element nodes in dom4j's representation of XML. So, I'm not sure SAX is incredibly faster. There might be a way to flatten out the tree and use just one big Handler in SAX. If so, speed will go up, but I tip my hat to James. I'll implement first, since dom4j coding is piece of cake, and if speed is an issue, I've architected to rip out the scanner and replace with SAX later on. Currently, it is taking 100 ms to scan my object, which is pretty good for me. If SAX can drop it to 30 or less, I'll look at it, otherwise, I doubt it matters. Both are considerably faster than Castor, which took 29s to deserialize. 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
