Create a new StAX reader based on a List of {@link XMLEvent}s.

@param paramEvents
{@link XMLEvent}s
@return an {@link XMLEventReader}
@throws IOException
if I/O operation fails
@throws XMLStreamException
if any parsing error occurs
972202
public static synchronized XMLEventReader createListReader(final List<XMLEvent> paramEvents)
        throws IOException, XMLStreamException {
        checkNotNull(paramEvents);
        return new ListEventReader(paramEvents);
    }
300763
@Override
    public List<Node> parse(String xml) throws ParseException {
        try {
            final SAXParserFactory factory = SAXParserFactory.newInstance();
            final SAXParser saxParser = factory.newSAXParser();
            final NodeXmlHandler handler = new NodeXmlHandler();

            saxParser.parse(new CharSequenceInputStream(xml, Charset.defaultCharset()), handler);

            return handler.getNodes();
        } catch (IOException ioe) {
            throw new ParseException(ioe);
        } catch (SAXException e) {
            throw new ParseException(e);
        } catch (ParserConfigurationException e) {
            throw new ParseException(e);
        }
    }
661355
public EventReader createReader() {
        return new EventReader(eventsProcessor, sourceFilter, eventFilter, progressReporter, exceptionHandler, sqsManager, s3Manager, config);
    }
190848
public static XElement parseXML(XMLStreamReader in) throws XMLStreamException {
        XElement root = parseXMLFragment(in);
        in.close();
        return root;
    }
981673
public void parseEvents(MarcXchangeEventConsumer consumer) throws XMLStreamException {
        Objects.requireNonNull(consumer);
        if (builder.getMarcListeners() != null) {
            for (Map.Entry<String, MarcListener> entry : builder.getMarcListeners().entrySet()) {
                consumer.setMarcListener(entry.getKey(), entry.getValue());
            }
        }
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        XMLEventReader xmlEventReader = inputFactory.createXMLEventReader(builder.getInputStream());
        while (xmlEventReader.hasNext()) {
            consumer.add(xmlEventReader.nextEvent());
        }
        xmlEventReader.close();
    }
1205031
public static <T> List<T> parseListFrom(XMLStreamReader parser, Schema<T> schema)
            throws IOException, XMLStreamException
    {
        if (parser.nextTag() != START_ELEMENT || !"list".equals(parser.getLocalName()))
            throw new XmlInputException("Expected token START_ELEMENT: list");

        // final String simpleName = schema.messageName();
        final ArrayList<T> list = new ArrayList<T>();
        final XmlInput input = new XmlInput(parser);

        for (int tag = parser.nextTag(); tag != END_ELEMENT; tag = parser.nextTag())
        {
            if (tag != START_ELEMENT || !schema.messageName().equals(parser.getLocalName()))
                throw new XmlInputException("Expected token START_ELEMENT: " + schema.messageName());

            final T message = schema.newMessage();

            if (parser.nextTag() == END_ELEMENT)
            {
                // if(!simpleName.equals(parser.getLocalName()))
                // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName);

                // empty message
                list.add(message);
                continue;
            }

            schema.mergeFrom(input, message);

            // if(!simpleName.equals(parser.getLocalName()))
            // throw new XmlInputException("Expecting token END_ELEMENT: " + simpleName);

            list.add(message);
        }

        return list;
    }
707106
public static MtasConfiguration readConfiguration(InputStream reader)
      throws IOException {
    MtasConfiguration currentConfig = null;
    // parse xml
    XMLInputFactory factory = XMLInputFactory.newInstance();
    try {
      XMLStreamReader streamReader = factory.createXMLStreamReader(reader);
      QName qname;
      try {
        int event = streamReader.getEventType();
        while (true) {
          switch (event) {
          case XMLStreamConstants.START_DOCUMENT:
            if (!streamReader.getCharacterEncodingScheme().equals("UTF-8")) {
              throw new IOException("XML not UTF-8 encoded");
            }
            break;
          case XMLStreamConstants.END_DOCUMENT:
          case XMLStreamConstants.SPACE:
            break;
          case XMLStreamConstants.START_ELEMENT:
            // get data
            qname = streamReader.getName();
            if (currentConfig == null) {
              if (qname.getLocalPart().equals("mtas")) {
                currentConfig = new MtasConfiguration();
              } else {
                throw new IOException("no Mtas Configuration");
              }
            } else {
              MtasConfiguration parentConfig = currentConfig;
              currentConfig = new MtasConfiguration();
              parentConfig.children.add(currentConfig);
              currentConfig.parent = parentConfig;
              currentConfig.name = qname.getLocalPart();
              for (int i = 0; i < streamReader.getAttributeCount(); i++) {
                currentConfig.attributes.put(
                    streamReader.getAttributeLocalName(i),
                    streamReader.getAttributeValue(i));
              }
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (currentConfig.parent == null) {
              return currentConfig;
            } else {
              currentConfig = currentConfig.parent;
            }
            break;
          case XMLStreamConstants.CHARACTERS:
            break;
          }
          if (!streamReader.hasNext()) {
            break;
          }
          event = streamReader.next();
        }
      } finally {
        streamReader.close();
      }
    } catch (XMLStreamException e) {
      log.debug(e);
    }
    return null;
  }
1162145
public static String encode(List<XMLEvent> theEvents) {
		try {
			StringWriter w = new StringWriter();
			XMLEventWriter ew = XmlUtil.createXmlFragmentWriter(w);

			for (XMLEvent next : theEvents) {
				if (next.isCharacters()) {
					ew.add(next);
				} else {
					ew.add(next);
				}
			}
			ew.close();
			return w.toString();
		} catch (XMLStreamException e) {
			throw new DataFormatException("Problem with the contained XML events", e);
		} catch (FactoryConfigurationError e) {
			throw new ConfigurationException(e);
		}
	}
369710
public static Node read(InputStream inputStream) throws XmlException
    {
        try
        {
            DocumentBuilderFactory documentBuilderFactory = 
                DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = 
                documentBuilderFactory.newDocumentBuilder();
            Document document = documentBuilder.parse(inputStream);
            Node node = document.getDocumentElement();
            return node;
        } 
        catch (ParserConfigurationException canNotHappen)
        {
            // Can not happen with a default configuration
            throw new XmlException("Could not create parser", canNotHappen);
        } 
        catch (SAXException e)
        {
            throw new XmlException("XML parsing error", e);
        }
        catch (IOException e)
        {
            throw new XmlException("IO error while reading XML", e);
        }

    }
146454
public XMLReader getXMLReader() throws SAXException
    {
        XMLFilter filter = _Verifier.getVerifierFilter();
        filter.setParent(_WrappedParser.getXMLReader());
        return filter;
    }
224692
@Override
    public XMLEventWriter createXMLEventWriter(Writer w, String enc)
        throws XMLStreamException
    {
        return new Stax2EventWriterImpl(createSW(null, w, enc, false));
    }
629383
public final void parse(InputStream stream) throws IOException {

        // all XML exceptions are wrapped by IOExceptions
        try {

            // setup a namespace aware SAXParserFactory
            SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            saxParserFactory.setNamespaceAware(true);

            // parse the input stream
            SAXParser parser = saxParserFactory.newSAXParser();
            parser.parse(stream, this);

        } catch (ParserConfigurationException e) {
            throw new IOException(e);
        } catch (SAXException e) {
            throw new IOException(e);
        }

    }
592290
private XMLEventWriter createXmlEventWriter(StringWriter stringWriter)
            throws FactoryConfigurationError, XMLStreamException {
        return new IndentingXMLEventWriter(XMLOutputFactory.newInstance()
                .createXMLEventWriter(stringWriter));
    }
850078
public static XMLStreamException unexpectedElement(final XMLExtendedStreamReader reader) {
        final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), reader.getLocation());

        return new XMLStreamValidationException(ex.getMessage(),
                                                ValidationError.from(ex, ErrorType.UNEXPECTED_ELEMENT)
                                                        .element(reader.getName()),
                                                ex);
    }
1317526
public boolean hasNextEvent() throws IOException {
        /* In Fasterxml parser, hasNextEvent will consume next token. So do not call it multiple times. */
        JsonToken nextToken = jsonParser.nextToken();
        return nextToken == JsonToken.START_OBJECT || nextToken == JsonToken.START_ARRAY;
    }
194227
protected void prepareXMLReader() throws VerifierConfigurationException {
		try {
			SAXParserFactory factory = SAXParserFactory.newInstance();
			factory.setNamespaceAware(true);
			reader = factory.newSAXParser().getXMLReader();
		} catch( SAXException e ) {
			throw new VerifierConfigurationException(e);
		} catch( ParserConfigurationException pce ) {
			throw new VerifierConfigurationException(pce);
		}
	}
1043766
public static XElement parseXML(InputStream in) throws XMLStreamException {
        XMLInputFactory inf = XMLInputFactory.newInstance();
        XMLStreamReader ir = inf.createXMLStreamReader(in);
        return parseXML(ir);
    }