private void handleStartElement() throws SAXException {
   if (getContentHandler() != null) {
     QName qName = this.reader.getName();
     if (hasNamespacesFeature()) {
       for (int i = 0; i < this.reader.getNamespaceCount(); i++) {
         startPrefixMapping(this.reader.getNamespacePrefix(i), this.reader.getNamespaceURI(i));
       }
       for (int i = 0; i < this.reader.getAttributeCount(); i++) {
         String prefix = this.reader.getAttributePrefix(i);
         String namespace = this.reader.getAttributeNamespace(i);
         if (StringUtils.hasLength(namespace)) {
           startPrefixMapping(prefix, namespace);
         }
       }
       getContentHandler()
           .startElement(
               qName.getNamespaceURI(),
               qName.getLocalPart(),
               toQualifiedName(qName),
               getAttributes());
     } else {
       getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes());
     }
   }
 }
  private Attributes getAttributes() {
    AttributesImpl attributes = new AttributesImpl();
    for (int i = 0; i < this.reader.getAttributeCount(); i++) {
      String namespace = this.reader.getAttributeNamespace(i);
      if (namespace == null || !hasNamespacesFeature()) {
        namespace = "";
      }
      String type = this.reader.getAttributeType(i);
      if (type == null) {
        type = "CDATA";
      }
      attributes.addAttribute(
          namespace,
          this.reader.getAttributeLocalName(i),
          toQualifiedName(this.reader.getAttributeName(i)),
          type,
          this.reader.getAttributeValue(i));
    }
    if (hasNamespacePrefixesFeature()) {
      for (int i = 0; i < this.reader.getNamespaceCount(); i++) {
        String prefix = this.reader.getNamespacePrefix(i);
        String namespaceUri = this.reader.getNamespaceURI(i);
        String qName;
        if (StringUtils.hasLength(prefix)) {
          qName = "xmlns:" + prefix;
        } else {
          qName = "xmlns";
        }
        attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
      }
    }

    return attributes;
  }
  private void handleStartDocument() throws SAXException {
    if (XMLStreamConstants.START_DOCUMENT == this.reader.getEventType()) {
      String xmlVersion = this.reader.getVersion();
      if (StringUtils.hasLength(xmlVersion)) {
        this.xmlVersion = xmlVersion;
      }
      this.encoding = this.reader.getCharacterEncodingScheme();
    }
    if (getContentHandler() != null) {
      final Location location = this.reader.getLocation();
      getContentHandler()
          .setDocumentLocator(
              new Locator2() {
                @Override
                public int getColumnNumber() {
                  return (location != null ? location.getColumnNumber() : -1);
                }

                @Override
                public int getLineNumber() {
                  return (location != null ? location.getLineNumber() : -1);
                }

                @Override
                public String getPublicId() {
                  return (location != null ? location.getPublicId() : null);
                }

                @Override
                public String getSystemId() {
                  return (location != null ? location.getSystemId() : null);
                }

                @Override
                public String getXMLVersion() {
                  return xmlVersion;
                }

                @Override
                public String getEncoding() {
                  return encoding;
                }
              });
      getContentHandler().startDocument();
      if (this.reader.standaloneSet()) {
        setStandalone(this.reader.isStandalone());
      }
    }
  }