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?
posted 12 years ago
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.