/* Implements XMLReader method.
343766
@Override
    public void parse(final String mSystemID) throws IOException, SAXException {
        emitStartDocument();
        try {
            super.call();
        } catch (final Exception exc) {
            exc.printStackTrace();
        }
        emitEndDocument();
    }
146454
public XMLReader getXMLReader() throws SAXException
    {
        XMLFilter filter = _Verifier.getVerifierFilter();
        filter.setParent(_WrappedParser.getXMLReader());
        return filter;
    }
229874
public synchronized Node parse(InputStream in) throws IOException, SAXException {
        //_dtd=null;
        Handler handler = new Handler();
        XMLReader reader = _parser.getXMLReader();
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);
        reader.setEntityResolver(handler);
        _parser.parse(new InputSource(in), handler);
        if (handler.error != null)
            throw handler.error;
        Node root = (Node)handler.root;
        handler.reset();
        return root;
    }
967247
@Override
  public void parseXml(Reader reader) throws IOException, XmlPullParserException {
    XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
    namespaceDictionary.set("", "");
    super.parseXml(reader, namespaceDictionary);
  }
190848
public static XElement parseXML(XMLStreamReader in) throws XMLStreamException {
        XElement root = parseXMLFragment(in);
        in.close();
        return root;
    }
857751
XMLReader newXMLReader() throws ParserConfigurationException, SAXException, FactoryConfigurationError {
		SAXParserFactory parserFactory = SAXParserFactory.newInstance();
		SAXParser saxParser = parserFactory.newSAXParser();
		XMLReader reader = saxParser.getXMLReader();
		reader.setContentHandler(this);
		return reader;
	}
378898
@Override
    public XMLEventReader createXMLEventReader(InputStream in)
        throws XMLStreamException
    {
        // false for auto-close, since caller has access to the input stream
        return new WstxEventReader(createEventAllocator(),
        		createSR(null, in, null, true, false));
    }
335631
public void parse(InputStream xmlInput) throws XMLStreamException {
    InputStream input = isoControlCharsAwareParser ? new ISOControlCharAwareInputStream(xmlInput) : xmlInput;
    parse(inf.rootElementCursor(input));
  }
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());
    }
311172
private void readXmlDeclaration() throws IOException, KriptonRuntimeException {
		if (bufferStartLine != 0 || bufferStartColumn != 0 || position != 0) {
			checkRelaxed("processing instructions must not start with xml");
		}

		read(START_PROCESSING_INSTRUCTION);
		parseStartTag(true, true);

		if (attributeCount < 1 || !"version".equals(attributes[2])) {
			checkRelaxed("version expected");
		}

		version = attributes[3];

		int pos = 1;

		if (pos < attributeCount && "encoding".equals(attributes[2 + 4])) {
			encoding = attributes[3 + 4];
			pos++;
		}

		if (pos < attributeCount && "standalone".equals(attributes[4 * pos + 2])) {
			String st = attributes[3 + 4 * pos];
			if ("yes".equals(st)) {
				standalone = Boolean.TRUE;
			} else if ("no".equals(st)) {
				standalone = Boolean.FALSE;
			} else {
				checkRelaxed("illegal standalone value: " + st);
			}
			pos++;
		}

		if (pos != attributeCount) {
			checkRelaxed("unexpected attributes in XML declaration");
		}

		isWhitespace = true;
		text = null;
	}
1143999
public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
        copy(reader, writer, false, false);
    }
787458
static boolean scanForChildTag(XMLStreamReader reader, String tagName)
			throws XMLStreamException {
		assert reader.isStartElement();

		int level = -1;
		while (reader.hasNext()) {
			//keep track of level so we only search children, not descendants
			if (reader.isStartElement()) {
				level++;
			} else if (reader.isEndElement()) {
				level--;
			}
			if (level < 0) {
				//end parent tag - no more children
				break;
			}

			reader.next();

			if (level == 0 && reader.isStartElement() && reader.getLocalName().equals(tagName)) {
				return true; //found
			}
		}
		return false; //got to end of parent element and not found
	}
524347
private XMLReader fetchSheetReader() throws SAXException {
		XMLReader xmlReader = null;
		try {
			xmlReader = XMLReaderFactory.createXMLReader(CLASS_SAXPARSER);
		} catch (SAXException e) {
			if (e.getMessage().contains("org.apache.xerces.parsers.SAXParser")) {
				throw new DependencyException(e, "You need to add 'xerces:xercesImpl' to your project and version >= 2.11.0");
			} else {
				throw e;
			}
		}
		xmlReader.setContentHandler(this);
		return xmlReader;
	}
774911
public void parse(String xmlInput, boolean strict) throws ParseException {
		if (xmlInput == null) {
			throw new IllegalArgumentException("input can not be null");
		}
		ArrayList splitContents = split(xmlInput, interpreteAsXHTML, true);
		build(splitContents, interpreteAsXHTML);
	}
709322
public void isWelformed(String xml) {
        StringReader reader = new StringReader(xml);
        XMLStreamReader r = null;
        try {
            r = XML_INPUT_FACTORY.createXMLStreamReader(reader);
            while (r.hasNext()) {
                r.next();
            }
        } catch (XMLStreamException e) {
            throw new RuntimeException(e);
        } finally {
            if (r != null) {
                try {
                    r.close();
                } catch (Exception e) {
                    // should not happen
                }
            }
            reader.close();
        }
    }
388396
public NodeConfig parser(InputStreamReader xml) throws UnmarshalException {

		NodeConfig config = new NodeConfig();
		SAXBuilder builder = new SAXBuilder(false);
		Document doc = null;

		try {
			doc = builder.build(xml);
			config = parserNode(doc.getRootElement());

			xml.close();
			return config;
		} catch (JDOMException e) {
			throw new UnmarshalException(e);
		} catch (IOException e) {
			throw new UnmarshalException(e);
		}
	}
754209
@Override
    public XMLStreamReader createXMLStreamReader(InputStream in)
        throws XMLStreamException
    {
        // false for auto-close, since caller has access to the input stream
        return createSR(null, in, null, false, false);
    }