static boolean scanForChildTag ( XMLStreamReader reader , String tagName ) throws XMLStreamException { assert reader . isStartElement ( ) ; int level = - 1 ; while ( reader . hasNext ( ) ) { //keep track of level so we only search children, not descendants if ( reader . isStartElement ( ) ) { level ++ ; } else if ( reader . isEndElement ( ) ) { level -- ; } if ( level < 0 ) { //end parent tag - no more children break ; } reader . next ( ) ; if ( level == 0 && reader . isStartElement ( ) && reader . getLocalName ( ) . equals ( tagName ) ) { return true ; //found } } return false ; //got to end of parent element and not found }
Scan xml for tag child of the current element