`
deepfuture
  • 浏览: 4426527 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80286
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70720
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103908
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:287231
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15112
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:68219
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32474
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46227
社区版块
存档分类
最新评论

lucene-使用Digester分析XML索引

阅读更多

1、隶属于Jakarta Commons项目的一个子项目提供了一个简单的上层接口来将XML类型的文档映射为JAVA对象。

2、DigesterXMLHandler类用来解析XML格式的文档。

public class DigesterXMLHandler implements DocumentHandler{

private Digester dig;

private static Documentdoc;

publicDigesterXMLHandler(){

dig=new Digester();

dig.setValidating(false);

//首先创建DigesterXMLHandler实例

dig.addObjectCreate("address-book",DigesterXMLHandler.class);

//找到contact子元素,创建一个contact类实例

dig.addObjectCreate("address-book/contact",Contact.class);

//当Digester找到<contact>参数的type属性时我们就需要设置Contact实例的type属性。

dig.adSetProperties("address-book","type","type");

//设置几个规则,用来设置contact属性。

dig.addCallMethod("address-book/contact/name","setName",0);

dig.addCallMethod("address-book/contact/address","setAddress",0);

dig.addCallMethod("address-book/contact/city","setCity",0);

dig.addCallMethod("address-book/contact/province","setProvince",0);

dig.addCallMethod("address-book/contact/postalcode","setPostalcode",0);

dig.addCallMethod("address-book/contact/country","setCountry",0);

dig.addCallMethod("address-book/contact/telephone","setTelephone",0);

dig.addSetNext("address-book/contact","populateDocument");

}

public sychronized DocumentgetDocument(InputStream is) throws DocumentHandlerException{

try{

dig.parse(is);//开始解析XML格式的InputStream 输入流
}

catch (IOException e){

throw new DocumentHandlerException("cannot parse XMLdocument",e);

}

catch (SAXExceptoin e){

throw new DocumentHandlerException("cannot parse XMLdocument",e);

}

return doc;

}

 

public voidpopulateDocument(Contact contact){

//将已经取出的各Field组装到Lucene的Document对象里

doc=new Document();

doc.add(Field.Keyword("type",contact.getType()));

doc.add(Field.Keyword("name",contact.getName()));

doc.add(Field.Keyword("address",contact.getAddress()));

doc.add(Field.Keyword("city",contact.getCity()));

doc.add(Field.Keyword("province",contact.getProvince()));

doc.add(Field.Keyword("postalcode",contact.getPostalcode()));

doc.add(Field.Keyword("country",contact.getCountry()));

doc.add(Field.Keyword("telephone",contact.getTelephone()));

}

//重载了每个contact实例入口的JAVABEAN类

public static class Contact{

private String type;

private String name;

private String address;

private String city;

private String province;

private String postalcode;

private String country;

private String telephone;

public void setType(String newType){

type=newType();

}

public String getType(){

return type;

}

public String setName(String newName){

name=newName;

}

public String getName(){

returnname;

}

..........//依次设置city、province、postalcode、country、telephone

..........

}

public static voidmain(String[] args) throws Exception{

DigesterXMLHandler handler=new DigesterXMLHandler();

Document doc=

handler.getDocument(new FileInputStream(new File(args[0]));

System.out.println(doc);

}

}

分享到:
评论

相关推荐

    lucene-analyzers-smartcn-7.7.0-API文档-中文版.zip

    赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...

    lucene-core-7.2.1-API文档-中文版.zip

    赠送jar包:lucene-core-7.2.1.jar; 赠送原API文档:lucene-core-7.2.1-javadoc.jar; 赠送源代码:lucene-core-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.2.1.pom; 包含翻译后的API文档:lucene...

    lucene-core-7.7.0-API文档-中文版.zip

    赠送jar包:lucene-core-7.7.0.jar; 赠送原API文档:lucene-core-7.7.0-javadoc.jar; 赠送源代码:lucene-core-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.7.0.pom; 包含翻译后的API文档:lucene...

    lucene-analyzers-common-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-analyzers-common-6.6.0.jar; 赠送原API文档:lucene-analyzers-common-6.6.0-javadoc.jar; 赠送源代码:lucene-analyzers-common-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-...

    lucene-4.7.0全套jar包

    - **Core模块**:这是Lucene的核心,包含了索引和搜索的基本功能,如`lucene-core-4.7.0.jar`。 - **Analyzer模块**:提供了各种分词器和过滤器,如`lucene-analyzers-common-4.7.0.jar`。 - **QueryParser模块**...

    lucene-suggest-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-suggest-6.6.0.jar; 赠送原API文档:lucene-suggest-6.6.0-javadoc.jar; 赠送源代码:lucene-suggest-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-6.6.0.pom; 包含翻译后的API...

    lucene-backward-codecs-7.3.1-API文档-中英对照版.zip

    赠送jar包:lucene-backward-codecs-7.3.1.jar; 赠送原API文档:lucene-backward-codecs-7.3.1-javadoc.jar; 赠送源代码:lucene-backward-codecs-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...

    lucene-core-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-core-6.6.0.jar; 赠送原API文档:lucene-core-6.6.0-javadoc.jar; 赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene...

    lucene-core-2.9.4,lucene-core-3.0.2,lucene-core-3.0.3,lucene-core-3.4.0

    - **多线程支持**:在3.0系列中,Lucene增强了对多线程环境的支持,允许并发索引和检索操作,提升性能。 3. **Lucene 3.4.0** - **查询执行优化**:3.4.0版本对查询执行引擎进行了重大优化,包括更快的评分计算和...

    lucene-spatial-extras-7.3.1-API文档-中英对照版.zip

    赠送jar包:lucene-spatial-extras-7.3.1.jar; 赠送原API文档:lucene-spatial-extras-7.3.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...

    lucene-memory-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-memory-6.6.0.jar; 赠送原API文档:lucene-memory-6.6.0-javadoc.jar; 赠送源代码:lucene-memory-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-memory-6.6.0.pom; 包含翻译后的API文档...

    lucene-analyzers-smartcn-7.7.0-API文档-中英对照版.zip

    赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...

    lucene-suggest-7.7.0-API文档-中文版.zip

    赠送jar包:lucene-suggest-7.7.0.jar; 赠送原API文档:lucene-suggest-7.7.0-javadoc.jar; 赠送源代码:lucene-suggest-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-suggest-7.7.0.pom; 包含翻译后的API...

    lucene-spatial-extras-7.2.1-API文档-中英对照版.zip

    赠送jar包:lucene-spatial-extras-7.2.1.jar; 赠送原API文档:lucene-spatial-extras-7.2.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...

    je-analysis-1.5.3、lucene-core-2.4.1分词组件

    使用"je-analysis-1.5.3"和"lucene-core-2.4.1"的组合,开发者可以构建出强大的文本搜索解决方案。在实际应用中,首先,Je-Analysis会处理输入的中文文本,进行分词操作,然后将分词结果传递给Lucene进行索引。当...

    lucene-sandbox-7.2.1-API文档-中文版.zip

    赠送jar包:lucene-sandbox-7.2.1.jar; 赠送原API文档:lucene-sandbox-7.2.1-javadoc.jar; 赠送源代码:lucene-sandbox-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-sandbox-7.2.1.pom; 包含翻译后的API...

    lucene-spatial-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-spatial-6.6.0.jar; 赠送原API文档:lucene-spatial-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-6.6.0.pom; 包含翻译后的API...

    lucene-misc-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-misc-6.6.0.jar; 赠送原API文档:lucene-misc-6.6.0-javadoc.jar; 赠送源代码:lucene-misc-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-misc-6.6.0.pom; 包含翻译后的API文档:lucene...

    lucene-spatial-extras-6.6.0-API文档-中英对照版.zip

    赠送jar包:lucene-spatial-extras-6.6.0.jar; 赠送原API文档:lucene-spatial-extras-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-extras-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...

    lucene-core-6.6.0-API文档-中英对照版.zip

    赠送jar包:lucene-core-6.6.0.jar; 赠送原API文档:lucene-core-6.6.0-javadoc.jar; 赠送源代码:lucene-core-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-6.6.0.pom; 包含翻译后的API文档:lucene...

Global site tag (gtag.js) - Google Analytics