<p>A hook for the SAX XML parser to call when this table has
been fully loaded from the XML, and all nested elements have
been processed.</p>

<p>Performs heavy indexing and naming of elements which weren't
provided with a name.</p>
196588
public function doFinalInitialization()
    {
        // Heavy indexing must wait until after all columns composing
        // a table's primary key have been parsed.
        if ($this->heavyIndexing) {
            $this->doHeavyIndexing();
        }

        // if idMethod is "native" and in fact there are no autoIncrement
        // columns in the table, then change it to "none"
        $anyAutoInc = false;
        foreach ($this->columns as $column) {
            if ($column->isAutoIncrement()) {
                $anyAutoInc = true;
            }
        }
        if (IdMethod::NATIVE === $this->getIdMethod() && !$anyAutoInc) {
            $this->setIdMethod(IdMethod::NO_ID_METHOD);
        }
    }
598588
public void warning(SAXParseException e) throws SAXException
  {
    // This is not great, but we really would rather have the error 
    // handler be the error listener if it is a error handler.  Coroutine's fatalError 
    // can't really be configured, so I think this is the best thing right now 
    // for error reporting.  Possibly another JAXP 1.1 hole.  -sb
    javax.xml.transform.ErrorListener errorListener = m_transformer.getErrorListener();
    if(errorListener instanceof ErrorHandler)
    {
      ((ErrorHandler)errorListener).warning(e);
    }
    else
    {
      try
      {
        errorListener.warning(new javax.xml.transform.TransformerException(e));
      }
      catch(javax.xml.transform.TransformerException te)
      {
        throw e;
      }
    }
  }
934737
private void setupParsing() throws SAXException{
        parent.setEntityResolver(handler);
        parent.setDTDHandler(handler);
        parent.setContentHandler(handler);
        parent.setErrorHandler(handler);
        parent.setProperty(SAXProperties.LEXICAL_HANDLER, handler);
        parent.setProperty(SAXProperties.DECL_HANDLER_ALT, handler);
    }
1211876
private void processEndTag() throws XMLStreamException, TTException {
        mLevelInToShredder--;

        if (mInserted) {
            mInsertedEndTag = true;
        }

        if (mRemovedNode) {
            mRemovedNode = false;
        } else {

            // Move cursor to parent.
            if (mWtx.getNode().getDataKey() == mLastNodeKey) {
                /*
                 * An end tag must have been parsed immediately before and it
                 * must have been an empty element at the end of a subtree, thus
                 * move this time to parent node.
                 */
                assert mWtx.getNode().hasParent() && mWtx.getNode().getKind() == IConstants.ELEMENT;
                mWtx.moveTo(mWtx.getNode().getParentKey());
            } else {
                if (mWtx.getNode().getKind() == IConstants.ELEMENT) {
                    final ElementNode element = (ElementNode)mWtx.getNode();
                    if (element.hasFirstChild() && element.hasParent()) {
                        // It's not an empty element, thus move to parent.
                        mWtx.moveTo(mWtx.getNode().getParentKey());
                    }
                    // } else {
                    // checkIfLastNode(true);
                    // }
                } else if (((ITreeStructData)mWtx.getNode()).hasParent()) {
                    if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) {
                        mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey());
                        /*
                         * Means next event is an end tag in StAX reader, but
                         * something different where the Treetank transaction
                         * points to, which also means it has to be deleted.
                         */
                        mKeyMatches = -1;
                        mDelete = EDelete.ATBOTTOM;
                        deleteNode();
                    }
                    mWtx.moveTo(mWtx.getNode().getParentKey());
                }

            }

            mLastNodeKey = mWtx.getNode().getDataKey();

            // Move cursor to right sibling if it has one.
            if (((ITreeStructData)mWtx.getNode()).hasRightSibling()) {
                mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getRightSiblingKey());
                mMovedToRightSibling = true;

                skipWhitespaces(mReader);
                if (mReader.peek().getEventType() == XMLStreamConstants.END_ELEMENT) {
                    /*
                     * Means next event is an end tag in StAX reader, but
                     * something different where the Treetank transaction points
                     * to, which also means it has to be deleted.
                     */
                    mKeyMatches = -1;
                    mDelete = EDelete.ATBOTTOM;
                    deleteNode();
                }
            } else {
                mMovedToRightSibling = false;
            }
        }
    }
595427
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
    public void warning(String msg, Exception ex) throws SAXException{
        xml.warning(new SAXParseException(msg, null, ex));
    }
635256
public void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh)
          throws org.xml.sax.SAXException
  {

    String str = str();

    lh.comment(str.toCharArray(), 0, str.length());
  }
1126165
void initXmlReader() throws SAXException {
        if (parserMap.containsKey(ATTR_FORMAT_VALUE_DITA)) {
            reader = XMLReaderFactory.createXMLReader(parserMap.get(ATTR_FORMAT_VALUE_DITA));
            final Map<String, Boolean> features = parserFeatures.getOrDefault(ATTR_FORMAT_VALUE_DITA, emptyMap());
            for (final Map.Entry<String, Boolean> feature : features.entrySet()) {
                try {
                    reader.setFeature(feature.getKey(), feature.getValue());
                } catch (final SAXNotRecognizedException e) {
                    // Not Xerces, ignore exception
                }
            }
        } else {
            reader = XMLUtils.getXMLReader();
        }

        reader.setFeature(FEATURE_NAMESPACE_PREFIX, true);
        if (validate) {
            reader.setFeature(FEATURE_VALIDATION, true);
            try {
                reader.setFeature(FEATURE_VALIDATION_SCHEMA, true);
            } catch (final SAXNotRecognizedException e) {
                // Not Xerces, ignore exception
            }
        }
        if (gramcache) {
            final XMLGrammarPool grammarPool = GrammarPoolManager.getGrammarPool();
            try {
                reader.setProperty(FEATURE_GRAMMAR_POOL, grammarPool);
                logger.info("Using Xerces grammar pool for DTD and schema caching.");
            } catch (final NoClassDefFoundError e) {
                logger.debug("Xerces not available, not using grammar caching");
            } catch (final SAXNotRecognizedException | SAXNotSupportedException e) {
                logger.warn("Failed to set Xerces grammar pool for parser: " + e.getMessage());
            }
        }

        CatalogUtils.setDitaDir(ditaDir);
        reader.setEntityResolver(CatalogUtils.getCatalogResolver());
    }
24920
protected final void readEndElem()
        throws XMLStreamException
    {
        mTokenState = TOKEN_FULL_COALESCED; // will be read completely

        if (mElementStack.isEmpty()) {
            // Let's just offline this for clarity
            reportExtraEndElem();
            return; // never gets here
        }

        char c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
            : getNextCharFromCurrent(SUFFIX_IN_CLOSE_ELEMENT);
        // Quick check first; missing name?
        if  (!isNameStartChar(c) && c != ':') {
            if (c <= CHAR_SPACE) { // space
                throwUnexpectedChar(c, "; missing element name?");
            }
            throwUnexpectedChar(c, "; expected an element name.");
        }

        /* Ok, now; good thing is we know exactly what to compare
         * against...
         */
        String expPrefix = mElementStack.getPrefix();
        String expLocalName = mElementStack.getLocalName();

        // Prefix to match?
        if (expPrefix != null && expPrefix.length() > 0) {
            int len = expPrefix.length();
            int i = 0;

            while (true){
                if (c != expPrefix.charAt(i)) {
                    reportWrongEndPrefix(expPrefix, expLocalName, i);
                    return; // never gets here
                }
                if (++i >= len) {
                    break;
                }
                c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
                    : getNextCharFromCurrent(SUFFIX_IN_CLOSE_ELEMENT);
            }
            // And then we should get a colon
            c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
                : getNextCharFromCurrent(SUFFIX_IN_CLOSE_ELEMENT);
            if (c != ':') {
                reportWrongEndPrefix(expPrefix, expLocalName, i);
                return;
            }
            c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
                : getNextCharFromCurrent(SUFFIX_IN_CLOSE_ELEMENT);
        }

        // Ok, then, does the local name match?
        int len = expLocalName.length();
        int i = 0;
        
        while (true){
            if (c != expLocalName.charAt(i)) {
                // Not a match...
                reportWrongEndElem(expPrefix, expLocalName, i);
                return; // never gets here
            }
            if (++i >= len) {
                break;
            }
            c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
                : getNextCharFromCurrent(SUFFIX_IN_CLOSE_ELEMENT);
        }

        // Let's see if end element still continues, however?
        c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
            : getNextCharFromCurrent(SUFFIX_IN_CLOSE_ELEMENT);
        if (c <= CHAR_SPACE) {
            c = getNextInCurrAfterWS(SUFFIX_IN_CLOSE_ELEMENT, c);
        } else if (c == '>') {
            ;
        } else if (c == ':' || isNameChar(c)) {
            reportWrongEndElem(expPrefix, expLocalName, len);
        }

        // Ok, fine, match ok; now we just need the closing gt char.
        if (c != '>') {
            throwUnexpectedChar(c, SUFFIX_IN_CLOSE_ELEMENT+" Expected '>'.");
        }

        // Finally, let's let validator detect if things are ok
        int vld = mElementStack.validateEndElement();
        mVldContent = vld;
        mValidateText = (vld == XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT);

        // Plus verify WFC that start and end tags came from same entity
        /* 13-Feb-2006, TSa: Are we about to close an element that
         *    started within a parent element?
         *    That's a GE/element nesting WFC violation...
         */
        if (mCurrDepth == mInputTopDepth) {
            handleGreedyEntityProblem(mInput);
        }
        --mCurrDepth;
    }
94832
protected void initNestedFormatters(Element element, CmsXmlContentDefinition contentDefinition)
    throws CmsXmlException {

        Iterator<Element> i = CmsXmlGenericWrapper.elementIterator(element, APPINFO_NESTED_FORMATTER);
        while (i.hasNext()) {
            // iterate all "default" elements in the "defaults" node
            Element handlerElement = i.next();
            String formatterElement = handlerElement.attributeValue(APPINFO_ATTR_ELEMENT);
            addNestedFormatter(formatterElement, contentDefinition);
        }
    }
6337
public void read(InputStream is, String encoding, final TagListener listener) {

		mSaxHandler.initialize();

		Reader reader = null;

		try {

			reader = new InputStreamReader(is, encoding);

			SAXParserFactory spf = SAXParserFactory.newInstance();

			// To correspond to a big entities
			spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);

			XMLReader xmlReader;

			xmlReader = spf.newSAXParser().getXMLReader();

			mSaxHandler.setTagEventListener(new TagEventListener() {

				@Override
				public void onTagStarted(String fullTagName, String tagName) {
					if (listener != null) {
						listener.onTagStarted(BigXmlReader.this, fullTagName, tagName);
					}
				}

				@Override
				public void onTagFinished(String fullTagName, String tagName, String value, Attributes atts) {
					if (listener != null) {
						listener.onTagFinished(BigXmlReader.this, fullTagName, tagName, value, atts);
					}
				}
			});

			xmlReader.setContentHandler(mSaxHandler);
			InputSource iso = new InputSource(reader);

			xmlReader.parse(iso);

		} catch (BasicSAXHandlerException e) {
			// Force stopped
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
784413
private void loadElement(Element element, Transform t)
			throws ParsingException {
		for (int i = 0; i < processors.size(); i++) {
			ElementProcessor processor = (ElementProcessor) processors.get(i);

			if (processor.handles(element)) {
				processor.process(this, element, diagram, t);
			}
		}
	}
1325379
@Override
	public void process(String xmlString, ITempelEntryProcessor entryProcessor) throws Exception {
		process(new ByteArrayInputStream(xmlString.getBytes()), entryProcessor);
	}
644485
function FeedParser() {
    this.current_tag = null;
    var parser       = this.parser = sax.parser(true,
        { trim: true
        , normalize: true
        })
      , _this        = this;
    
    parser.onopentag  = function(tag) { _this.open(tag); };
    parser.onclosetag = function(tag) { _this.close(tag); };
    
    parser.onerror = function() { this.error = undefined; }
    parser.ontext  = function(text) { _this.ontext(text); };
    parser.oncdata = function(text) { _this.ontext(text); };
    parser.onend   = function() { _this.onend(); };
  }
153455
public synchronized Node parse(String xml) throws IOException, SAXException {
        ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
        return parse(is);
    }
593012
public static void setHandler(XMLReader reader, Object handler) throws SAXNotSupportedException, SAXNotRecognizedException{
        if(handler instanceof ContentHandler)
            reader.setContentHandler((ContentHandler)handler);
        if(handler instanceof EntityResolver)
            reader.setEntityResolver((EntityResolver)handler);
        if(handler instanceof ErrorHandler)
            reader.setErrorHandler((ErrorHandler)handler);
        if(handler instanceof DTDHandler)
            reader.setDTDHandler((DTDHandler)handler);
        if(handler instanceof LexicalHandler){
            try{
                reader.setProperty(SAXProperties.LEXICAL_HANDLER, handler);
            }catch(SAXException ex){
                reader.setProperty(SAXProperties.LEXICAL_HANDLER_ALT, handler);
            }
        }
        if(handler instanceof DeclHandler){
            try{
                reader.setProperty(SAXProperties.DECL_HANDLER, handler);
            }catch(SAXException ex){
                reader.setProperty(SAXProperties.DECL_HANDLER_ALT, handler);
            }
        }
    }
117112
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs)
    throws SAXException
    {
        if (logger.isLoggable(Level.FINER)) logger.exiting(className, "startElement(String,String,String,org.xml.sax.Attributes)");

        Properties props = new Properties();
        int attrLength = attrs.getLength();
        for (int i = 0; i < attrLength; i++)
        {
            props.put(attrs.getQName(i), attrs.getValue(i));
        }

        JSONObject obj = new JSONObject(localName, props);
        if (this.head == null)
        {
            this.head    = obj;
            this.current = head;
        }
        else
        {
            if (current != null)
            {
                this.previousObjects.push(current);
                this.current.addJSONObject(obj);
            }
            this.current  = obj;
        }

        if (logger.isLoggable(Level.FINER)) logger.exiting(className, "startElement(String,String,String,org.xml.sax.Attributes)");
    }
958314
@Override
  public Result<MZXMLIndexElement> buildIndex(final IndexBuilder.Info info) throws Exception {
    Result<MZXMLIndexElement> result = new IndexBuilder.Result<>(info);

    int numOpeningScanTagsFound = 0;
    vars.reset();

    XMLStreamReaderImpl reader = (pool == null) ? new XMLStreamReaderImpl() : pool.borrowObject();
    try {
      reader.setInput(info.is, StandardCharsets.UTF_8.name());
      LogHelper.setJavolutionLogLevelFatal();

      final XMLStreamReaderImpl.LocationImpl location = reader.getLocation();
      int eventType = XMLStreamConstants.END_DOCUMENT;
      CharArray localName, attr;
      Attributes attrs;
      do {
        // Read the next XML element
        try {
          eventType = reader.next();
        } catch (XMLStreamException e) {

          if (e instanceof XMLUnexpectedEndTagException) {
            // it's ok to have unexpected closing tags
            eventType = reader.getEventType();
          } else if (e instanceof XMLUnexpectedEndOfDocumentException) {
            // as we're reading arbitrary chunks of file, we will almost always finish parsing by hitting this condition
            break;
          } else {
            throw new FileParsingException(e);
          }
        }

        // Process the read event
        switch (eventType) {

          case XMLStreamConstants.START_ELEMENT:
            localName = reader.getLocalName();
            attrs = reader.getAttributes();

            if (localName.contentEquals(MZXMLMultiSpectraParser.TAG.SCAN.name)) {
              if (vars.offsetLo != null) {
                // this means we've encountered nested Spectrum tags
                long lastStartTagPos = location.getLastStartTagPos();
                vars.length = (int) (vars.offsetLo - lastStartTagPos);
                addAndFlush(result, info.offsetInFile);
              }

              //tagScanStart(reader);
              vars.offsetLo = location.getLastStartTagPos();
              try {
                vars.scanNumRaw = attrs.getValue(MZXMLMultiSpectraParser.ATTR.SCAN_NUM.name)
                    .toInt();
              } catch (NumberFormatException e) {
                throw new FileParsingException("Malformed scan number while building index", e);
              }

            }
            break;

          case XMLStreamConstants.CHARACTERS:
            break;

          case XMLStreamConstants.END_ELEMENT:
            localName = reader.getLocalName();

            if (localName.contentEquals(MZXMLMultiSpectraParser.TAG.SCAN.name)) {
              vars.offsetHi = location.getTotalCharsRead();
              addAndFlush(result, info.offsetInFile);
            }

            break;
        }
      } while (eventType != XMLStreamConstants.END_DOCUMENT);

    } finally {
      addAndFlush(result, info.offsetInFile);

      // we need to return the reaer to the pool, if we borrowed it from there
      if (pool != null && reader != null) {
        pool.returnObject(reader);
      }
    }

    return result;
  }