XStream解析xml
来源:互联网 发布:图模型 知乎 编辑:程序博客网 时间:2024/04/20 13:01
这个工具之前没用过,这次为了解析stock data使用了下,还是比较好用的
这是最后的调用
XStream xstream = new XStream(new DomDriver());xstream.processAnnotations(ControlList.class);xstream.autodetectAnnotations(true);ControlList list = (ControlList) xstream.fromXML(xml);
下面是List对象
@XStreamAlias("control")public class ControlList {@XStreamImplicit(itemFieldName = "content")private List<Content> content;
下面是属性对象,这里要注意,如果不是属性,那就只需要@XStreamAlias就可以了
@XStreamAlias("content")public class Content {@XStreamAsAttribute@XStreamAlias("d")private String date;
XML数据如下:
<pre name="code" class="html">- <control> <content d="2014-01-02" o="11.400" h="11.530" c="11.460" l="11.260" v="229859" bl="" /> <content d="2014-01-03" o="11.340" h="11.380" c="11.190" l="11.110" v="262835" bl="" /> <content d="2014-01-06" o="11.140" h="11.420" c="11.320" l="10.850" v="354200" bl="" />
工具类,读取xml数据
<pre name="code" class="html">private String connReadData(String url) {StringBuffer sb = new StringBuffer();try {URL httpUrl = new URL(url);URLConnection connection = httpUrl.openConnection();BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));String line = null;while ((line = br.readLine()) != null) {sb.append(line);}if (br != null) {br.close();br = null;}} catch (Exception e) {e.printStackTrace();}return sb.toString();}
郑州就维软件
0 0
- 解析XML XStream
- 用xstream解析XML
- 使用xstream解析xml
- xml 解析 Xstream
- XStream解析xml文件
- android xstream 解析xml
- XStream解析xml
- XStream解析XMl文件
- XStream解析XML字符串
- XStream解析XML
- 利用xstream解析xml
- XStream解析xml
- Xstream解析XML文件
- Xstream解析XML文件
- Xstream解析XML
- 用Xstream解析XML
- xStream解析XML
- xStream解析xml文件
- 一念成龙
- 【OC学习-28】自定义对象的归档和解归档:例子说明以及简单总结
- GCC 编译使用动态链接库和静态链接库的方法
- Mysql查询一段时间记录
- ipad4使用教程 ipad mini使用技巧
- XStream解析xml
- 前端设计师
- OSB Message-Level Custom Security
- 黑马程序员-java中IO流的操作总结2
- SQL Error:ORA-01658:无法为表空间USERS中的段创建INITIAL区
- 图示Hadoop MapReduce的生命周期
- container_of 宏
- c++跨平台编译
- C++设计模式——单例模式