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 ); } } |
<org.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="//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 "//welcome-file-list/welcome-file" Parser.installSaxParser: <org.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="//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 "//welcome-file-list/welcome-file" Parser.installSaxParser: <org.apache.xerces.parsers.SAXParser> installed successfully 1: indexing web.xml |
本文转自: http://www.elook.net.cn/cms/Site/Article/wlbch15/XMLWML413/52192_P2.html
Query: ( // ( / welcome-file-list welcome-file ) )