import javax.xml.stream.*; import java.io.*; public class XMLParserExample { public static void main(String[] args) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); InputStream stream = new FileInputStream("input.xml"); XMLStreamReader reader = factory.createXMLStreamReader(stream); while (reader.hasNext()) { int eventType = reader.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { String elementName = reader.getLocalName(); System.out.println("Element name: " + elementName); int attributeCount = reader.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { String attributeName = reader.getAttributeName(i).toString(); String attributeValue = reader.getAttributeValue(i); System.out.println("Attribute name: " + attributeName); System.out.println("Attribute value: " + attributeValue); } } } } }In this example, we are parsing an XML document and printing out each element and its attributes using the getAttributeName() method to retrieve the attribute names. The javax.xml.stream package is part of the Java SE standard library.