public void endElement(String uri, String name, String qName) {

    if (qName.equals("instanceId")) {
      this.instanceId = currentOrNull();
    } else if (qName.equals("shutdownState") || qName.equals("currentState")) {
      inCurrentState = false;
    } else if (qName.equals("previousState")) {
      inPreviousState = false;
    } else if (qName.equals("name")) {
      if (inCurrentState) {
        shutdownState = InstanceState.fromValue(currentOrNull());
      } else if (inPreviousState) {
        previousState = InstanceState.fromValue(currentOrNull());
      }
    } else if (qName.equals("item")) {
      String region = EC2Utils.findRegionInArgsOrNull(request);
      if (region == null) region = defaultRegion;
      instances.add(new InstanceStateChange(region, instanceId, shutdownState, previousState));
      this.instanceId = null;
      this.shutdownState = null;
      this.previousState = null;
    }

    currentText = new StringBuilder();
  }
  public void endElement(String uri, String localName, String qName) {
    // if end tag is one of below then set inXYZ to false
    if (qName.equals("ListenerDescriptions")) {
      inListenerDescriptions = false;
    } else if (qName.equals("AppCookieStickinessPolicies")) {
      inAppCookieStickinessPolicies = false;
    } else if (qName.equals("LBCookieStickinessPolicies")) {
      inLBCookieStickinessPolicies = false;
    } else if (qName.equals("LoadBalancerDescriptions")) {
      inLoadBalancerDescriptions = false;
    } else if (qName.equals("Instances")) {
      inInstances = false;
    } else if (qName.equals("AvailabilityZones")) {
      inAvailabilityZones = false;
    }

    if (qName.equals("DNSName")) {
      elb.setDnsName(currentText.toString().trim());
    } else if (qName.equals("LoadBalancerName")) {
      elb.setName(currentText.toString().trim());
    } else if (qName.equals("InstanceId")) {
      elb.getInstanceIds().add(currentText.toString().trim());
    } else if (qName.equals("member")) {

      if (inAvailabilityZones) {
        elb.getAvailabilityZones().add(currentText.toString().trim());
      } else if (!(inListenerDescriptions
          || inAppCookieStickinessPolicies
          || inInstances
          || inLBCookieStickinessPolicies
          || inAvailabilityZones)) {
        try {
          String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
          if (region == null) region = defaultRegion;

          elb.setRegion(region);
          contents.add(elb);
        } catch (NullPointerException e) {
          logger.warn(e, "malformed load balancer: %s", localName);
        }

        this.elb = null;
      }
    }

    currentText = new StringBuilder();
  }