File tree Expand file tree Collapse file tree 1 file changed +50
-1
lines changed
marklogic-client-api/src/main/java/com/marklogic/client/datamovement Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -373,7 +373,7 @@ T getNextHandle() {
373373 break checkForHandle ;
374374
375375 case PROCESS :
376- T handle = visitor .makeBufferedHandle (xmlStreamReader );
376+ T handle = visitor .makeBufferedHandle (new XMLBranchStreamReader ( xmlStreamReader ) );
377377 if (handle != null ) {
378378 return handle ;
379379 }
@@ -466,4 +466,53 @@ public boolean tryAdvance(Consumer<? super DocumentWriteOperation> action) {
466466 }
467467 }
468468
469+ private static class XMLBranchStreamReader extends StreamReaderDelegate {
470+ private int depth = 1 ;
471+
472+ XMLBranchStreamReader (XMLStreamReader reader ) {
473+ super (reader );
474+ }
475+
476+ public boolean hasNext () {
477+ return (depth > 0 );
478+ }
479+
480+ public int next () throws XMLStreamException {
481+ if (depth < 1 ) {
482+ return XMLStreamReader .END_DOCUMENT ;
483+ }
484+
485+ int next = super .next ();
486+ if (depth >= 1 ) {
487+ if (next == XMLStreamReader .START_ELEMENT ) {
488+ depth ++;
489+ }
490+ if (next == XMLStreamReader .END_ELEMENT ) {
491+ depth --;
492+ }
493+ }
494+
495+ return next ;
496+ }
497+
498+ public int nextTag () throws XMLStreamException {
499+ if (depth < 1 ) {
500+ return XMLStreamReader .END_DOCUMENT ;
501+ }
502+ int next = super .nextTag ();
503+ if (next == XMLStreamReader .START_ELEMENT ) {
504+ depth ++;
505+ }
506+ if (next == XMLStreamReader .END_ELEMENT ) {
507+ depth --;
508+ }
509+
510+ return next ;
511+ }
512+
513+ public void close () {
514+ throw new UnsupportedOperationException ("Current XML branch cannot be closed." );
515+ }
516+ }
517+
469518}
You can’t perform that action at this time.
0 commit comments