.xstream的alias使用方法
来源:互联网 发布:淘宝网psv带游戏 编辑:程序博客网 时间:2024/04/29 19:41
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
0 0
- .xstream的alias使用方法
- xstream.alias("","")
- XStream的使用方法
- xstream别名alias
- Ubuntu16.04 alias的使用方法
- XStream使用方法
- XStream使用方法
- XStream使用方法
- bash alias 终极使用方法
- alias使用方法小结
- JavaWeb开发中alias拦截器的使用方法
- xstream+xpp超强黄金组合使用方法
- xstream+xpp超强黄金组合使用方法
- xstream+xpp超强黄金组合使用方法
- nginx root、alias、location指令使用方法
- nginx root、alias、location指令使用方法
- Xstream的使用
- XStream的分析
- 第7章 函数--C++的编程模块
- 读书名单
- hibernate多对一单向关联
- 【连载】我要锻炼身体
- c++中,什么时候用 A a;和什么时候用A a=new A;
- .xstream的alias使用方法
- SDUT 2446 最终排名
- 嵌入式学习入门之路
- Activity生命周期
- Redis的高级应用-安全性和主从复制
- 堆排序
- RTC学习笔记
- Hive优化总结
- Evade antivirus convert shellcode to c