Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.StringReader;

public class Main {
    private static XMLInputFactory xmlInputFactory;

    /**
     * Get the XML string as a StAX stream reader instance.
     * @param string a string containing XML
     * @return An <tt>XMLStreamReader</tt> instance wrapping the XML string
     * @throws XMLStreamException if something went wrong
     */
    public static XMLStreamReader getStringAsXMLStreamReader(final String string) throws XMLStreamException {
        if (xmlInputFactory == null) {
            createXMLInputFactory();
        }

        // Give the string to the StAX reader
        return xmlInputFactory.createXMLStreamReader(new StringReader(string));
    }

    private static void createXMLInputFactory() {
        // Create the factory
        xmlInputFactory = XMLInputFactory.newInstance();
        xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
    }
}