xstream 别名的用法
来源:互联网 发布:js左右滑动图片轮播 编辑:程序博客网 时间:2024/05/17 08:05
1.xstream的alias使用方法:
1.1 作用:将序列化中的类全量名称,用别名替换。
1.2 使用方法:xstream.alias("blog", Blog.class);
1.3 示例:
要序列化的类:
package test.xstream.test;
public class Author {
private String name;
public Author(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
不使用别名alias时序列化出来的xml:
<test.xstream.test.Author>
<name>name</name>
</test.xstream.test.Author>
使用别名alias时序列化出来的xml:
<Author>
<name>name</name>
</Author>
2.xstream的aliasField
2.1 作用:使用别名替代属性名
2.2 使用方法:xstream.aliasField("author", Author.class, "name");
2.3 示例:
不使用别名aliasField时序列化出来的xml:
<Author>
<name>name</name>
</Author>
使用别名aliasField时序列化出来的xml:
<Author>
<author>name</author>
</Author>
3. xstream的useAttributeFor
3.1 作用:将某一个类的属性,作为xml头信息的属性,而不是子节点
3.2 使用方法:xstream.useAttributeFor(Author.class, "name");
3.3 示例: 不使用别名useAttributeFor时序列化出来的xml:
<Author> <author>name</author> </Author>
使用别名useAttributeFor时序列化出来的xml:
<Author name="name"/>
ps: 使用方法
public static void main(String[] args) {
XStream xstream = new XStream();
xstream.alias("Author", Author.class);
// xstream.aliasField("author", Author.class, "name");
xstream.useAttributeFor(Author.class, "name");
Author author =new Author("name");
String xmlString =xstream.toXML(author);
System.out.println(xmlString);
}
几个相关网址:http://xstream.codehaus.org/alias-tutorial.html
http://blog.csdn.net/faye0412/article/details/6602144
1.1 作用:将序列化中的类全量名称,用别名替换。
1.2 使用方法:xstream.alias("blog", Blog.class);
1.3 示例:
要序列化的类:
package test.xstream.test;
public class Author {
private String name;
public Author(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
不使用别名alias时序列化出来的xml:
<test.xstream.test.Author>
<name>name</name>
</test.xstream.test.Author>
使用别名alias时序列化出来的xml:
<Author>
<name>name</name>
</Author>
2.xstream的aliasField
2.1 作用:使用别名替代属性名
2.2 使用方法:xstream.aliasField("author", Author.class, "name");
2.3 示例:
不使用别名aliasField时序列化出来的xml:
<Author>
<name>name</name>
</Author>
使用别名aliasField时序列化出来的xml:
<Author>
<author>name</author>
</Author>
3. xstream的useAttributeFor
3.1 作用:将某一个类的属性,作为xml头信息的属性,而不是子节点
3.2 使用方法:xstream.useAttributeFor(Author.class, "name");
3.3 示例: 不使用别名useAttributeFor时序列化出来的xml:
<Author> <author>name</author> </Author>
使用别名useAttributeFor时序列化出来的xml:
<Author name="name"/>
ps: 使用方法
public static void main(String[] args) {
XStream xstream = new XStream();
xstream.alias("Author", Author.class);
// xstream.aliasField("author", Author.class, "name");
xstream.useAttributeFor(Author.class, "name");
Author author =new Author("name");
String xmlString =xstream.toXML(author);
System.out.println(xmlString);
}
几个相关网址:http://xstream.codehaus.org/alias-tutorial.html
http://blog.csdn.net/faye0412/article/details/6602144
1 0
- xstream 别名的用法
- xstream 别名的用法
- xstream 别名的用法
- xstream 别名的用法
- xstream 别名的用法
- xstream的别名使用
- XStream的基本用法
- XStream的基本用法
- XStream别名指南
- XStream别名指南
- XStream别名指南
- XStream别名指南
- XStream指定别名
- xstream别名alias
- Spring OXM-XStream使用别名
- 利用XStream将List<String>转为xml后指定String的别名
- xstream,节点属性起别名时这样的问题你遇到过吗
- 关于XStream相关的常用方法;设置别名;忽略属性;设置xml字段属性
- 降低Nginx代理服务器的磁盘IO使用率,提高转发性能
- jQueryMobile 属性一览
- 用VB做通讯录
- Linux 3.2中回写机制的变革
- java TreeSet
- xstream 别名的用法
- 计算几何--求凸包模板--Graham算法--poj 1113
- java邮箱开发代码——发邮件
- 休闲小游戏新鲜出炉咯!
- zoj 3633 Alice's present(离线+线段树)
- Ubuntu安装android
- C语言 ANSI-C内存管理API函数整理
- android横竖屏切换时候Activity的生命周期
- gedit配置