import java.io.*; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import org.apache.xerces.util.* ; import org.apache.xerces.impl.*; import org.apache.xerces.parsers.*; import org.apache.xerces.jaxp.*; public class ReadAttributes { public static void main(String[] args) { try { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a xml file name: "); String xmlFile = bf.readLine(); File file = new File(xmlFile); if (file.exists()){ //SAX-implementation: SAXParserFactory factory = SAXParserFactory.newInstance(); // Create SAX-parser SAXParser parser = factory.newSAXParser(); System.out.println("Name:\t" + "Value:"); //Define a handler SaxHandler handler = new SaxHandler(); // Parse the xml document parser.parse(xmlFile, handler); } else{ System.out.println("File not found!"); } } catch (Exception e) { e.printStackTrace(); } } private static class SaxHandler extends DefaultHandler { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXParseException,SAXException { int length = attrs.getLength(); //Each attribute for (int i=0; i