I understand the basics of parsing an XML document with handlers, and  
the use of onStart() and onEnd().
However, I write to ask what kinds of information are available when  
the onStart() method is triggered.

Background:
I'm processing potentially large XML files that have structures like

<foo feature="value">
  <bar>...</bar>
  <bar>...</bar>
  ...
</foo>

wherein I might do well to capture each <bar> element and then detach  
it, to avoid keeping too much
XML structure in memory.   But before processing (and detaching) all  
the <bar> elements, I need
to get the value of the 'feature' attribute in the <foo> start tag.

If I have a handler like this

reader.addHandler("/foo", new ElementHandler() {

        public void onStart(ElementPath path) {

                // here I'd like to access the value of the 'feature' attribute,
                // but WITHOUT retrieving the whole <foo> element

                // this seems to work
                String val = path.getCurrent().attribute("feature").getValue() ;
                // but I worry about calling getCurrent()
        }
        public void onEnd(ElementPath path) {}
}

reader.addHandler("/foo/bar", new ElementHandler() {
        public void onStart(ElementPath path) {}

        public void onEnd(ElementPath path) {
                Element elmt = path.getCurrent() ;
                // do something with this <bar> element
                elmt.detach() ;
        }
}

Questions:

1.  What kinds of information are available when onStart() is  
invoked?  Are the start-tag attributes accessible without calling  
getCurrent()?

2.  In the onStart() method, when I invoke  
path.getCurrent().attribute("feature").getValue(), does the entire  
<foo> element get parsed into memory?
That's what I want to avoid.  When I encounter the <foo  
feature="value"> start tag, I'd just like to have access to the  
attributes.

Many thanks,

Ken

******************************
Kenneth R. Beesley, D.Phil.
P.O. Box 540475
North Salt Lake, UT
84054  USA






------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to