FileInputStream fis = new FileInputStream(f);
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser saxParser = factory.newSAXParser();//sax解析的,直接继承DefaultHandler
MyHandler1 handler = new MyHandler1(fis);
saxParser.parse(fis, handler);在handler的事件处理中,我如何才能获取fis流的位置啊?
我试着将fis传入到handler里面,调用available函数,一开始输出一个有效数字,再之后就全部是0了,有哪位有办法解决这个问题的?感激不尽!
如果能够有其他方法,既能进行sax解析xml文件,又能够定位文件流的位置也可以。
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser saxParser = factory.newSAXParser();//sax解析的,直接继承DefaultHandler
MyHandler1 handler = new MyHandler1(fis);
saxParser.parse(fis, handler);在handler的事件处理中,我如何才能获取fis流的位置啊?
我试着将fis传入到handler里面,调用available函数,一开始输出一个有效数字,再之后就全部是0了,有哪位有办法解决这个问题的?感激不尽!
如果能够有其他方法,既能进行sax解析xml文件,又能够定位文件流的位置也可以。
因此,你可以重载此方法,看能不能拿到一个location,只要拿到locator,就可以获得当前的行、列。如果没有,可以换一家XML类库试试。
---------------
public void setDocumentLocator(Locator locator)Receive an object for locating the origin of SAX document events.
SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the ContentHandler interface.The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.
Parameters:
locator - An object that can return the location of any SAX document event.
See Also:
Locator
...
MyHandler1 handler = new MyHandler1(f);
...
handler触发事件时,对file进行处理,还是不能得到流的位置啊。
不好意思,fis.getChannel不是public方法。