同情lz,ms现在很少人用sax解析xml,过时了,
用dom4j超简单的,几句就可以,性能也是众所周之的,
lz就不要重新造轮子
解决方案 »
- weblogic取得时间后面多个.0!这个问题怎么解决。急急急急急
- spring连接数据源简历表,但在Oracle里select * from tab查不出
- servlet如何直接向jsp打印字符
- 哥么们救命!!!!!hibernate配置文件有错吗
- webservice客户端出错,请大神帮忙
- 问大家一个struts+hibernate的问题!急!急!
- rtf文件的处理
- JBuilder中开发EJB
- Hibernate4+springmvc4 aop配置事务不回滚。100%结贴,在线等,急急急急....
- bejson今日新增 json字符串转成java的实体类POJO代码
- 滑动条问题
- java.lang.NullPointerException出错
<?xml version="1.0" encoding="UTF-8"?>
<setting>
<nameset>
<book>sax解析xml中出现问题效率比较低及复件 (36) 中国传统文化.ppt</book>
</nameset>
</setting>package mytest;import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;public class SaxTest { /**
* @param args
* @throws SAXException
*/
public static void main(String[] args) throws SAXException {
// TODO Auto-generated method stub
XMLReader reader = XMLReaderFactory.createXMLReader() ;
ContentHandler contentHandler = new MyContentHandler();
reader.setContentHandler( contentHandler );
try{
reader.parse("setting.xml");
}catch(Exception e){
e.printStackTrace();
}
}}class MyContentHandler implements ContentHandler {
private StringBuffer buf; public void setDocumentLocator(Locator locator) {
} public void startDocument() throws SAXException {
buf = new StringBuffer();
} public void endDocument() throws SAXException {
} public void processingInstruction(String target, String instruction)
throws SAXException {
} public void startPrefixMapping(String prefix, String uri) {
} public void endPrefixMapping(String prefix) {
} public void startElement(String namespaceURI, String localName,
String fullName, Attributes attributes) throws SAXException {
} public void endElement(String namespaceURI, String localName,
String fullName) throws SAXException {
String nullStr = "";
if (!buf.toString().trim().equals(nullStr)) {
if (fullName.trim().equals("book")) {
System.out.println(buf.toString().trim());
}
}
buf.setLength(0);
} public void characters(char[] chars, int start, int length)
throws SAXException {
buf.append(chars, start, length);
} public void ignorableWhitespace(char[] chars, int start, int length)
throws SAXException {
} public void skippedEntity(String name) throws SAXException {
}
}