转载自:http://www.ibm.com/developerworks/cn/xml/x-xstream/
这个例子中
Writer类将类Employee以xml的形式写入文件
Reader类将xml转化为Employee类的实例。
XtreamTest 读取xml文件将xml中的各个节点变为属性。
Config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<datasource-name>IRIS</datasource-name>
<ipaddress>9.124.74.85</ipaddress>
<logfilename>DailyLogApplication.log</logfilename>
<appender>console</appender>
</config>
package com.xtream;
public class Employee {
private String name;
private String designation;
private String department;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return "Name : " + this.name + "\nDesignation : " + this.designation + "\nDepartment : " + this.department;
}
}
package com.xtream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.thoughtworks.xstream.XStream;
public class Writer {
public static void main(String[] args) {
Employee e = new Employee();
// Set the properties using the setter methods
// Note: This can also be done with a constructor.
// Since we want to show that XStream can serialize
// even without a constructor, this approach is used.
e.setName("Jack");
e.setDesignation("Manager");
e.setDepartment("Finance");
// Serialize the object
XStream xs = new XStream();
// Write to a file in the file system
try {
FileOutputStream fs = new FileOutputStream("D:/workspace/TestProject/src/com/xtream/employeedata.xml");
xs.toXML(e, fs);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
}
package com.xtream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.thoughtworks.xstream.*;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class Reader {
public static void main(String[] args) {
XStream xs = new XStream(new DomDriver());
Employee e = new Employee();
try {
FileInputStream fis = new FileInputStream("D:/workspace/TestProject/src/com/xtream/employeedata.xml");
xs.fromXML(fis, e);
// print the data from the object that has been read
System.out.println(e.toString());
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
}
package com.xtream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.thoughtworks.xstream.*;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class XtreamTest {
String datasourcename = null;
String ipaddress = null;
String logfilename = null;
String appender = null;
@Override
public String toString() {
// This method prints out the values stored in the member variables
return "Datasource Name : " + datasourcename + " \nIP Address : " + ipaddress + " \nLogfilename : " + logfilename + " \nAppender : " + appender;
}
/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
XStream xs = new XStream(new DomDriver());
FileInputStream fis = new FileInputStream("D:/workspace/TestProject/src/com/xtream/Config.xml");
xs.aliasField("datasource-name", XtreamTest.class, "datasourcename");
xs.alias("config", XtreamTest.class);
XtreamTest r = (XtreamTest) xs.fromXML(fis);
System.out.println(r.toString());
}
}
分享到:
相关推荐
ai插件 Xtream Path_汉化版
Xtream ToolKit 使用总结 Xtream ToolKit 使用总结 Xtream ToolKit 使用总结Xtream ToolKit 使用总结
CValley Xtream Path是一款国外开发的超强大的Adobe Illustrator的路径编辑插件。使用Xtream Path可以实现很多对于路径的操作(拖曳,拉伸,推动等),当编辑路径时也不会受控制点的约束,允许把路径拖曳到任何地方,...
CValley Xtream Path是一款国外开发的超强大的Adobe Illustrator的路径编辑插件。使用Xtream Path可以实现很多对于路径的操作(拖曳,拉伸,推动等),当编辑路径时也不会受控制点的约束,允许把路径拖曳到任何地方,...
将其放到AI CS5的Plug-ins里即可在工具栏调用
Xtream_Path illustrator插件 一个超棒的使用的illustrator插件
xtream path 1 5 for cs6亲测有效 里面有注册码 32位和64位的都有 安装方法不再赘述 功能非常强大的一个插件 还有插件使用说明书 绝对的极品珍惜资源 学AI必备
AI圆角插件 - CValley Xtream Path v1.6 for Adobe Illustrator - FOSI 相信大家和足迹一样,从Adobe CS6出世的那天就在等待同版本的圆角插件的面世,有的恐怕和足迹一样为了使用圆角插件而选择安装两个版本的ai,...
NULL 博文链接:https://wang38361640.iteye.com/blog/621735
Now with Xtream Path, you can drag anywhere on a path without fiddling around with direction lines and control points. Boasting 36 useful tools, filters, and effects, it gives you the flexibility ...
好用的illustrator 路径编辑插件,支持cs4 解压后复制到Adobe Illustrator CS4\Plug-ins\Tools文件夹,运行ai后,点击该工具,会出现注册信息,复制,注册,OK
如果您正在寻找仅用于提交一些查询的基于Java的cep,则有更好的选择(例如Esper),但是如果您需要一个简单易懂的CEP库来对其进行处理,扩展,使用它,尤其是用于研究流处理,Xtream是最佳选择。 我在MSc和PhD时代...
是一个很好的界面库,可以解决MFC界面不够完美的问题
jackson xtream应用
《Illustrator圆角插件:Xtream Path 1.3汉化版(CS至CS5通常)
可用的xstream的所有依赖包
包含xtream相关jar包,项目导入运行即可简单测试,实现xml与java对象的相互转化
xtream-codes-api-v2 最终公开的Xtream-Codes API V2官方正式文档,该文档在现已终止的xtream-codes.com论坛上发布原始网址: : 作者:BlackDream
很好用的一个AI倒角插件,序列号在nfo文件中,
Xtream UI 旨在使用带有自定义配置文件和简单样式的 bbLean 替换 Windows 资源管理器。 由于项目的性质,构建(32 位/64 位)确实需要匹配,因此,安装程序被锁定到预期平台。 注意:我们不是从源代码构建,我们从 ...