addHandler(String path,ElementHandler handler)
这个path貌似不能用xpath,最后用了最傻的 /xx/yy/zz/aaa/bb/ccc的形式,就好使了。 ------------------------------- // enable pruning mode to call me back as each ROW is complete SAXReader reader = new SAXReader(); reader.addHandler( "/ROWSET/ROW", new ElementHandler() { public void onStart(ElementPath path) { // do nothing here... } public void onEnd(ElementPath path) { // process a ROW element Element row = path.getCurrent(); Element rowSet = row.getParent(); Document document = row.getDocument(); ... // prune the tree row.detach(); } } );
Document document = reader.read(new StringReader("<xxx>..</xxx>"));
// The document will now be complete but all the ROW elements // will have been pruned. // We may want to do some final processing now ...
|