加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用 XStream 读写 XML 文件

发布时间:2020-12-16 08:43:08 所属栏目:百科 来源:网络整理
导读:使用 XStream 读写 XML 文件 导入 gradle 依赖: compile 'com.thoughtworks.xstream:xstream:1.4.8' compile 'dom4j:dom4j:1.6.1' // 写入 xml 文件 // http://wenku.baidu.com/link?url=OsNoP52Gl_MGUVmoAks9aS4cHz9_8HfdKwz3yHanK9B1U2Q8p-OIfU0St32BQGjd

使用 XStream 读写 XML 文件

导入 gradle 依赖:

compile 'com.thoughtworks.xstream:xstream:1.4.8'
compile 'dom4j:dom4j:1.6.1'
// 写入 xml 文件 // http://wenku.baidu.com/link?url=OsNoP52Gl_MGUVmoAks9aS4cHz9_8HfdKwz3yHanK9B1U2Q8p-OIfU0St32BQGjd4XuP5Mm0t7nU82ULz9Yme_3pg0EcY8SRbHZrQ61ugS3 XStream xStream = new XStream(new Dom4JDriver()); // new StaxDriver() Corpus corpus = new Corpus(); corpus.setCorpusWordList(corpusBeanList); // 参考资料:http://blog.sina.com.cn/s/blog_77a2f9ae01017ucf.html // 不显示集合元素标签 // addImplicitCollection(Class ownerType,String fieldName),去掉集合类型生成xml的父节点。 xStream.addImplicitCollection(Corpus.class,"corpusWordList"); xStream.alias("corpus",Corpus.class); xStream.alias("CorpusWord",CorpusWord.class); PrintWriter pw = new PrintWriter("corpus.xml","utf-8"); xStream.toXML(corpus,pw);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读