javax.xml.stream


1. Parsing XML with StAX (Streaming API for XML)

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

public class StAXParser {

    public static void main(String[] args) throws XMLStreamException {
        // Create an XMLInputFactory instance
        XMLInputFactory factory = XMLInputFactory.newInstance();

        // Create an XMLEventReader instance from the XML file
        XMLEventReader reader = factory.createXMLEventReader(new FileInputStream("example.xml"));

        // Iterate over the XML events and print them out
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            System.out.println(event);
        }
    }
}

2. Writing XML with StAX

3. Transforming XML with StAX

4. Validating XML with StAX

5. Generating XML with JAXB

6. Unmarshalling XML with JAXB

7. Parsing XML with JDOM