private void parse(XMLStreamReader parser,Handler handler,Map<String,Object> values,Stack<Set<String>> stack,boolean recordStarted) throws IOException, XMLStreamException {
  Set<String> valuesAddedinThisFrame=null;
  if (isRecord) {
    recordStarted=true;
    valuesAddedinThisFrame=new HashSet<>();
    stack.push(valuesAddedinThisFrame);
  }
 else   if (recordStarted) {
    valuesAddedinThisFrame=stack.peek();
  }
  try {
    if (attributes != null) {
      for (      Node node : attributes) {
        String value=parser.getAttributeValue(null,node.name);
        if (value != null || (recordStarted && !isRecord)) {
          putText(values,value,node.fieldName,node.multiValued);
          valuesAddedinThisFrame.add(node.fieldName);
        }
      }
    }
    Set<Node> childrenFound=new HashSet<>();
    int event=-1;
    int flattenedStarts=0;
    StringBuilder text=new StringBuilder();
    while (true) {
      event=parser.next();
      if (event == END_ELEMENT) {
        if (flattenedStarts > 0)         flattenedStarts--;
 else {
          if (hasText && valuesAddedinThisFrame != null) {
            valuesAddedinThisFrame.add(fieldName);
            putText(values,text.toString(),fieldName,multiValued);
          }
          if (isRecord)           handler.handle(getDeepCopy(values),forEachPath);
          if (childNodes != null && recordStarted && !isRecord && !childrenFound.containsAll(childNodes)) {
            for (            Node n : childNodes) {
              if (!childrenFound.contains(n))               n.putNulls(values,valuesAddedinThisFrame);
            }
          }
          return;
        }
      }
 else       if (hasText && (event == CDATA || event == CHARACTERS || event == SPACE)) {
        text.append(parser.getText());
      }
 else       if (event == START_ELEMENT) {
        if (flatten)         flattenedStarts++;
 else         handleStartElement(parser,childrenFound,handler,values,stack,recordStarted);
      }
 else       if (event == END_DOCUMENT)       return;
    }
  }
  finally {
    if ((isRecord || !recordStarted) && !stack.empty()) {
      Set<String> cleanThis=stack.pop();
      if (cleanThis != null) {
        for (        String fld : cleanThis)         values.remove(fld);
      }
    }
  }
}

private void parse ( XMLStreamReader parser , Handler handler , Map < String , Object > values , Stack < Set < String > > stack , boolean recordStarted ) throws IOException , XMLStreamException { Set < String > valuesAddedinThisFrame = null ; if ( isRecord ) { recordStarted = true ; valuesAddedinThisFrame = new HashSet < > ( ) ; stack . push ( valuesAddedinThisFrame ) ; } else if ( recordStarted ) { valuesAddedinThisFrame = stack . peek ( ) ; } try { if ( attributes != null ) { for ( Node node : attributes ) { String value = parser . getAttributeValue ( null , node . name ) ; if ( value != null || ( recordStarted && ! isRecord ) ) { putText ( values , value , node . fieldName , node . multiValued ) ; valuesAddedinThisFrame . add ( node . fieldName ) ; } } } Set < Node > childrenFound = new HashSet < > ( ) ; int event = - 1 ; int flattenedStarts = 0 ; StringBuilder text = new StringBuilder ( ) ; while ( true ) { event = parser . next ( ) ; if ( event == END_ELEMENT ) { if ( flattenedStarts > 0 ) flattenedStarts -- ; else { if ( hasText && valuesAddedinThisFrame != null ) { valuesAddedinThisFrame . add ( fieldName ) ; putText ( values , text . toString ( ) , fieldName , multiValued ) ; } if ( isRecord ) handler . handle ( getDeepCopy ( values ) , forEachPath ) ; if ( childNodes != null && recordStarted && ! isRecord && ! childrenFound . containsAll ( childNodes ) ) { for ( Node n : childNodes ) { if ( ! childrenFound . contains ( n ) ) n . putNulls ( values , valuesAddedinThisFrame ) ; } } return ; } } else if ( hasText && ( event == CDATA || event == CHARACTERS || event == SPACE ) ) { text . append ( parser . getText ( ) ) ; } else if ( event == START_ELEMENT ) { if ( flatten ) flattenedStarts ++ ; else handleStartElement ( parser , childrenFound , handler , values , stack , recordStarted ) ; } else if ( event == END_DOCUMENT ) return ; } } finally { if ( ( isRecord || ! recordStarted ) && ! stack . empty ( ) ) { Set < String > cleanThis = stack . pop ( ) ; if ( cleanThis != null ) { for ( String fld : cleanThis ) values . remove ( fld ) ; } } } }
this is the method where all the xml parsing happens . for each tag / subtag read from the source , this method is called recursively .
