你可以在想退出的地方抛出一个SAXException异常退出解析过程
解决方案 »
- webservice返回过来的字符串日期转换问题
- lucene+heritrix做个局域网搜索引擎
- "==" 对于非基本类型比较的是地址,那么对于基本类型呢?比较的是值还是地址?
- 请问哪里有ibm的java虚拟机下载?
- 贴子回复次数大于跟给分次数 不让结贴怎么办?
- HttpUrlConnection访问网页问题
- 关于数字签名的问题?急!!!
- 怎么样修改一个form中的tab键的顺序!!急
- Eclipse中调用javax.swing的问题
- CannotGetJdbcConnectionException.SQLException cannot be resolved to a type
- 50分提问★关于applet用户界面的问题!swing高手进来看看!
- java小问题
private Date fileBeginDate;
private Date fileEndDate;
public String name;
private XMLReader parser = new XMLReaderImpl(); public DbXmlFile(){
} public Date getFileCreateDate() {
return fileCreateDate;
} public void setFileCreateDate(Date fileCreateDate) {
this.fileCreateDate = fileCreateDate;
} public Date getFileBeginDate() {
return fileBeginDate;
} public void setFileBeginDate(Date fileBeginDate) {
this.fileBeginDate = fileBeginDate;
} public Date getFileEndDate() {
return fileEndDate;
} public void setFileEndDate(Date fileEndDate) {
this.fileEndDate = fileEndDate;
} public void startElement(String uri, String localName, String tag,
Attributes attribs)
throws SAXParseException {
if (localName.equals("ROOT")) {
String beginDate = attribs.getValue("beginDate");
String endDate = attribs.getValue("endDate");
this.fileBeginDate=Date.valueOf(beginDate );
this.fileEndDate=Date.valueOf(endDate);
System.out.println("date=============="+fileBeginDate);//这里已经set过了,但最后取不到啊
//throw new SAXParseException("sss",new LocatorImpl());
}
} public String parse(File xmlFile) throws FileNotFoundException, IOException,Exception
{ Reader in = new BufferedReader(new InputStreamReader(new
FileInputStream(xmlFile), "UTF8"));
try {
parser.setContentHandler(new DbXmlFile());
parser.parse(new InputSource(in));
} catch (SAXException saxe) {
if (saxe instanceof SAXParseException) {
SAXParseException saxpe = (SAXParseException) saxe;
int line = saxpe.getLineNumber();
int col = saxpe.getColumnNumber();
String publicID = saxpe.getPublicId();
String message = "XML parsing exception (" + publicID +
") line " + line + ":" + col;
throw new Exception(message);
}
}
return this.fileBeginDate.toString();
} public static void main(String[] args) throws Exception
{
DbXmlFile dbXmlFile = new DbXmlFile();
File file = new File("d:\\project\\xfk\\db\\date\\20040916134141601.xml");
System.out.println(dbXmlFile.parse(file));
System.out.println("beginDate--------------------------------"+ dbXmlFile.getFileBeginDate());///为什么这里打出的是NULL呢,在程序里面这个值已经设过了,怎么没取道啊
}
}最后取出的beginDate都是null,为什么啊
这边了,也打印出来了,但在最后System.out.println("beginDate--------------------------------"+ dbXmlFile.getFileBeginDate());///为什么这里打出的是NULL呢
在外面就打取不到啊,
如果你只是想知道根的属性,何必用sax,自己写个函数,把根的属性读出来不就行了。
如果你只是想知道根的属性,何必用sax,自己写个函数,把根的属性读出来不就行了。
你是说用dom来解析吗,但xml很大时,不是要全部加载进去,这样不是很耗内存吗