saxparser解析xml文件

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
XMLReader reader = factory.newSAXParser().getXMLReader();
reader.setContentHandler(new MyContentHandler());
FileReader fr = new FileReader("E:\\apache-tomcat\\webapps\\AAA\\resources.xml");
reader.parse(new InputSource(new StringReader("")));
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

}





public class MyContentHandler extends DefaultHandler {

private String tabName;

@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
super.characters(ch, start, length);
}


@Override
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
super.endDocument();
}


@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(uri, localName, qName);
}


@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
super.startDocument();
}


@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
super.startElement(uri, localName, qName, attributes);
}

}

你可能感兴趣的:(apache,tomcat,xml)