首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

saxparser解析xml资料

2012-11-07 
saxparser解析xml文件public class Main {/** * @param args */public static void main(String[] args) {

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);
}

}

热点排行