Example usage for javax.xml.stream XMLInputFactory newInstance

List of usage examples for javax.xml.stream XMLInputFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory newInstance.

Prototype

public static XMLInputFactory newInstance() throws FactoryConfigurationError 

Source Link

Document

Creates a new instance of the factory in exactly the same manner as the #newFactory() method.

Usage

From source file:FISTest.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    FileInputStream fis = new FileInputStream("c.xml");
    XMLStreamReader reader = factory.createXMLStreamReader(fis);
    reader.close();/*from  w w  w. j  a  v  a  2  s  . com*/
    fis.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader sr = factory.createXMLStreamReader(new FileReader("test.xml"));
    System.out.println(sr.getClass());

    while (sr.hasNext()) {
        int eventType = sr.next();

        if (eventType == XMLStreamReader.START_DOCUMENT) {
            continue;
        } else if (eventType == XMLStreamReader.END_ELEMENT) {
            System.out.println("End Element:    " + sr.getLocalName());
        } else if (eventType == XMLStreamReader.START_ELEMENT) {
            System.out.println("Start Element:  " + sr.getLocalName());
        }/* w w  w. j  av a  2 s  . co  m*/
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLEventReader xmler = xmlif.createXMLEventReader(new FileReader("yourFile.xml"));
    XMLEvent event;/*from   w w w . j av a 2s . c  om*/
    while (xmler.hasNext()) {
        event = xmler.nextEvent();
        if (event.isStartElement()) {
            System.out.println(event.asStartElement().getName());
        } else if (event.isCharacters()) {
            System.out.println(event.asCharacters().getData());
        }
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLStreamReader xmlsr = xmlif.createXMLStreamReader(new FileReader("points.xml"));
    int eventType;
    while (xmlsr.hasNext()) {
        eventType = xmlsr.next();// w w  w.  jav  a 2 s .c om
        switch (eventType) {
        case XMLEvent.START_ELEMENT:
            System.out.println(xmlsr.getName());
            break;
        case XMLEvent.CHARACTERS:
            System.out.println(xmlsr.getText());
            break;
        default:
            break;
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml")));

    int eventTypeID = reader.nextTag();
    reader.require(XMLStreamConstants.START_ELEMENT, null, "person");

    eventTypeID = reader.nextTag();/* w ww  .  j  ava  2 s  .co m*/
    reader.require(XMLStreamConstants.START_ELEMENT, null, "first_name");
    System.out.println(reader.getElementText());

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    File file = new File("test.xml");

    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file));

    while (reader.getEventType() == 6)
        reader.next();//from w  w  w.j  a  v  a 2 s  .c om

    int eventTypeID = reader.next();
    System.out.println("Hello " + reader.getText());
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    File file = new File("text.xml");

    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file));

    int eventTypeID = reader.nextTag();

    eventTypeID = reader.nextTag();//from  w w w .ja v  a2 s  .  c om

    eventTypeID = reader.next();
    System.out.println("Hello " + reader.getText());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();

    Reader fileReader = new FileReader("source.xml");
    XMLStreamReader reader = factory.createXMLStreamReader(fileReader);

    while (reader.hasNext()) {
        process(reader);/*from  w ww  .j  a va2s  . c o m*/
        reader.next();
    }
}

From source file:EntityReferenceTest.java

public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);

    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml"));
    while (reader.hasNext()) {
        int event = reader.next();
        if (event == XMLStreamConstants.CHARACTERS)
            System.out.println(reader.getText());
        else if (event == XMLStreamConstants.ENTITY_REFERENCE) {
            System.out.println("en: " + reader.getLocalName());
            System.out.println("er: " + reader.getText());
        }//from  w  ww  .  j a v a 2s  .co m
    }
    inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);

    reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml"));
    while (reader.hasNext()) {
        int event = reader.next();
        if (event == XMLStreamConstants.CHARACTERS)
            System.out.println(reader.getText());
        else if (event == XMLStreamConstants.ENTITY_REFERENCE) {
            System.out.println("en: " + reader.getLocalName());
            System.out.println("er: " + reader.getText());
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String filename = "yourXML.xml";

    XMLInputFactory factory = XMLInputFactory.newInstance();
    System.out.println("FACTORY: " + factory);

    XMLEventReader r = factory.createXMLEventReader(filename, new FileInputStream(filename));

    while (r.hasNext()) {
        XMLEvent e = r.nextEvent();
        System.out.println(e.toString());
    }/*from  w w w  .j a v  a  2  s .com*/
}