File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Confusing - defer-node-expansion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Confusing - defer-node-expansion" Watch "Confusing - defer-node-expansion" New topic

Confusing - defer-node-expansion


Joined: Jul 20, 2003
Posts: 6
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("", 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?

Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
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.
I agree. Here's the link:
subject: Confusing - defer-node-expansion
It's not a secret anymore!