Create XML StAX reader from data string - Java XML

Java examples for XML:StAX

Description

Create XML StAX reader from data string

Demo Code


//package com.java2s;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import java.io.*;

public class Main {
    public static void main(String[] argv) throws Exception {
        String xmlData = "java2s.com";
        System.out.println(createXmlReader(xmlData));
    }/*from  w w  w  . j  a v a  2  s .  c  o  m*/

    /**
     * Create XML reader from data string
     *
     * @param xmlData
     * @return
     * @throws XMLStreamException
     */
    static XMLEventReader createXmlReader(String xmlData)
            throws XMLStreamException {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        return inputFactory.createXMLEventReader(new StringReader(xmlData));
    }
}

Related Tutorials