public XMLInputSaxFieldRetriever(
     LogChannelInterface log, String sourceFile, XMLInputSaxMeta meta) {
   this.log = log;
   for (int i = 0; i < meta.getInputPosition().length; i++) {
     this.pathToRootElement.add(meta.getInputPosition()[i]);
   }
   this.meta = meta;
   this.sourceFile = sourceFile;
   fields = new ArrayList<XMLInputSaxField>();
 }
  // Event Handlers
  public void startElement(String uri, String localName, String qName, Attributes attributes)
      throws SAXException {
    // set the _counter level
    position[_counter + 1] += 1;
    _counter++;
    try {
      if (!rootFound) {
        XMLInputSaxFieldPosition el = null;

        try {
          el = (XMLInputSaxFieldPosition) pathToRootElement.get(counter);
        } catch (IndexOutOfBoundsException e) {
          throw new SAXException(e);
        }
        if ((counter == _counter) && qName.equalsIgnoreCase(el.getName())) {
          if (el.getType() == XMLInputSaxFieldPosition.XML_ELEMENT_ATT) {
            String att1 = attributes.getValue(el.getAttribute()); // must throw exception
            String att2 = el.getAttributeValue();
            if (att1.equals(att2)) {
              _pathToRootElement.add(
                  new XMLInputSaxFieldPosition(
                      qName, el.getAttribute(), el.getAttributeValue())); // to test with clone
              if (counter == pathToRootElement.size() - 1) {
                for (int i = 0; i < attributes.getLength(); i++) {
                  XMLInputSaxFieldPosition tempP =
                      new XMLInputSaxFieldPosition(
                          attributes.getQName(i), XMLInputSaxFieldPosition.XML_ATTRIBUTE, i + 1);
                  _pathToRootElement.add(tempP);
                  XMLInputSaxFieldPosition[] path =
                      new XMLInputSaxFieldPosition[_pathToRootElement.size()];
                  _pathToRootElement.toArray(path);
                  _pathToRootElement.remove(_pathToRootElement.size() - 1);
                  XMLInputSaxField tempF = new XMLInputSaxField(tempP.getName(), path);
                  if (!fields.contains(tempF)) {
                    fields.add(tempF);
                  }
                }
              }
              counterUp();
            } else {
              _pathToRootElement.add(
                  new XMLInputSaxFieldPosition(
                      qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1));
            }
          } else {
            _pathToRootElement.add(
                new XMLInputSaxFieldPosition(
                    qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1));
            counterUp();
          }
        } else {
          _pathToRootElement.add(
              new XMLInputSaxFieldPosition(
                  qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1));
        }
      } else {
        XMLInputSaxField temp = null;
        if (attributes.getValue(meta.getDefiningAttribute(qName)) == null) {
          _pathToRootElement.add(
              new XMLInputSaxFieldPosition(
                  qName, XMLInputSaxFieldPosition.XML_ELEMENT_POS, position[_counter] + 1));
          XMLInputSaxFieldPosition[] path = new XMLInputSaxFieldPosition[_pathToRootElement.size()];
          _pathToRootElement.toArray(path);
          temp = new XMLInputSaxField(naming(path), path);
        } else {
          String attribute = meta.getDefiningAttribute(qName);
          _pathToRootElement.add(
              new XMLInputSaxFieldPosition(qName, attribute, attributes.getValue(attribute)));
          XMLInputSaxFieldPosition[] path = new XMLInputSaxFieldPosition[_pathToRootElement.size()];
          _pathToRootElement.toArray(path);
          temp = new XMLInputSaxField(naming(path), path);
        }

        if (!fields.contains(temp)) {
          fields.add(temp);
        }
      }
    } catch (KettleValueException e) {
      log.logError(Const.getStackTracker(e));
      throw new SAXException(
          _counter
              + ","
              + counter
              + ((XMLInputSaxFieldPosition) _pathToRootElement.get(_pathToRootElement.size() - 1))
                  .toString(),
          e);
    }
  }