import java.io.*; import com.fatdog.textEngine.XmlEngine; import com.fatdog.textEngine.exceptions.*; import com.fatdog.textEngine.query.XQLResultListener; public class Search implements XQLResultListener { public static void main( String[] args ) { XmlEngine engine = new XmlEngine(); String searchFile = args[0]; String searchType = args[1]; String query = args[2]; try { file://配置引擎 engine.setSaxParserName( "org.apache.xerces.parsers.SAXParser"); engine.setMinIndexableWordLength( 3 ); engine.setDoIndexNumbers( false ); engine.setDocument( searchFile ); if (searchType.equals("1")) { engine.setListenerType( XmlEngine.STANDARD_LISTENER); } else if (searchType.equals("2")) { engine.setListenerType( XmlEngine.SUMMARY_LISTENER); } else { engine.setListenerType( XmlEngine.CSV_LISTENER); } } catch( MissingOrInvalidSaxParserException e ){ System.out.println( "缺少或不可用的 SAX解析器" ); return; } catch( FileNotFoundException e ) { System.out.println( "不能找到 XML 文件: "); return; } catch( CantParseDocumentException e ) { System.out.println( "不能解析 XML 文件: "); return; } // engine.printSessionStats(); engine.addXQLResultListener( new Search() ); try { engine.setQuery( query ); } catch( InvalidQueryException e ) { System.out.println( "不可用的查詢請求: " + e.getMessage() ); return; } } public void results( String xqlResults ) { System.out.println( xqlResults ); } } |
<o(jì)rg.apache.xerces.parsers.SAXParser> installed successfully 1: indexing web.xml Query: ( // ( / welcome-file-list welcome-file ) ) 3 hit(s) for file://welcome-file-list/welcome-file <?xml version="1.0"?> <xql:result query="http://welcome-file-list/welcome-file" hitCount="3" elemCount="3" docCount="1" xmlns:xql="http://www.fatdog.com/ Standard_Listener.html"> <welcome-file> index.jsp </welcome-file> <welcome-file> index.html </welcome-file> <welcome-file> index.htm </welcome-file> </xql:result> |
C:\xql\xql1>java Search web.xml 2 "http://welcome-file-list/welcome-file" Parser.installSaxParser: <o(jì)rg.apache.xerces.parsers.SAXParser> installed successfully 1: indexing web.xml Query: ( // ( / welcome-file-list welcome-file ) ) 3 hit(s) for file://welcome-file-list/welcome-file <?xml version="1.0"?> <xql:result query="http://welcome-file-list/welcome-file" hitCount="3" elemCount="3" docCount="1" xmlns:xql="http://www.fatdog.com/ Summary_Listener.html"> <welcome-file xql:docID="0" xql:elemIx="270"/> <welcome-file xql:docID="0" xql:elemIx="271"/> <welcome-file xql:docID="0" xql:elemIx="272"/> </xql:result> |
C:\xql\xql1>java Search web.xml 3 "http://welcome-file-list/welcome-file" Parser.installSaxParser: <o(jì)rg.apache.xerces.parsers.SAXParser> installed successfully 1: indexing web.xml Query: ( // ( / welcome-file-list welcome-file ) ) 3 hit(s) for file://welcome-file-list/welcome-file 3,3,1,0 0,270,welcome-file 0,271,welcome-file 0,272,welcome-file |
標(biāo)簽:黃石 西雙版納 益陽 宿遷 拉薩 寧夏 果洛 德州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《學(xué)習(xí)使用XML引擎XQEngine》,本文關(guān)鍵詞 學(xué)習(xí),使用,XML,引擎,XQEngine,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。