This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusing - defer-node-expansion

 
RichardLeeOne
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use Xerces DOM parser to parse a relative large XML file. In order to save memory usage, I am trying to set a defer-node-expansion feature to be true - by parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true).
My question is: by setting this feature, I am quite confusing about when the XML node is going to be expanded?
I am using a JTree to display this xml file. In this case, does this mean that:
1). Initially the DOM parser only parses the top level document element, and when user clicks a child element, it continues to parse the document?
2). After a node is expanded, if I make one node in the JTree collapsed using mouse click, and then expand it again, will the DOM parser parses the collpased part again when it is to be expanded?
3). Same as case2, but after a node is collapsed, if I set the collapsed node in JTree to null, and then expand it, will the DOM parser parses the collpased part again when it is to be expanded?

Thanks!
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best is to take a look at the source code to see what it exactly does when you set that feature on.
However, I've a guess. Parsing is finished by SAX completely. The parsing you mentioned will never hapen again. What is happening is they don't build that branch or part of XML into memory until it is used. This is done by JDOM long time ago. Glad to see DOM added this feature. It is called lazy initialization design pattern.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic