XStream: Java to XML and Back

The Problem Statement

XStream can be used to convert a Java Object to XML and back. This tutorial aims to create a java representation of the BBC RSS. We will start with a Simple java class and gradually start adding complexity to it so that it can be converted to the BBC RSS. Note that if you are looking at a way to parse an XML, it would be a good idea to first build a java class that XStream can convert to the required XML. XStream can then use the same class to deserialize the XML. First, have a look at the BBC RSS. Your browser would have formatted it to html so look at the source to see the XML. The parent element is ‘rss’. It has a child element called ‘channel’. The ‘channel’ has some properties (title, link, image etc) and a list of news ‘item’(s). Each ‘item’ has properties set on it (title, description etc). The aim is to create a Java class that XStream can convert to the BBC RSS.

Creating an XStream Instance

The first step is to create an instance of com.thoughtworks.xstream.XStream. This class is a facade to the XStream API and provides all major functionalities. If this class does not solve your problem then you could directly call the API methods. After obtaining the instance of XStream use the fromXML method to convert the XML to a java object. Note that creating an XStream instance is an expensive operation. It is therefore advisable to create a proper instance once and then reuse it for multiple calls (even in parallel). The setup is not threadsafe but any subsequent marshalling/unmarshalling is threadsafe.

Xstream: Introduction

What is XStream

XStream is a java library to convert Java Object into XML and back. You can take nearly every arbitrary deeply nested object turn it to XML and read it back without further configuration. You’re done if all you want to have is a persisted object in XML. XStream’s power lies in its extensive list of ‘Converters’ that help convert a wide variety of Java Objects to XML and vice versa. A Converter is a class that specifies how a Java Object should be serialized to XML. XStream comes bundled with a lot of Converters and you can also customize your own.

XStream allows converting a class to XML without modifying the class. It can serialize private and final fields and also inner classes. It can serialize references to objects. XStream has also added security measures that allows you to selectively de-serialize and serialize based on type.

SimpleXML: Example

This page provides a series of examples illustrating how a class can be annotated. It acts as a quick and dirty overview of how the framework can be used and also acts as a reference page. All examples can be downloaded for convenience. For further information take a look at the Tutorial.

§Creating nested path elements

Here an example of how to use the Path annotation to create nested elements and attributes using a single annotated class. Below is an example showing two elements nested within a XPath expression.

@Root
public class Example {

   @Path("a/b[1]")
   @Element
   private String x;

   @Path("a/b[2]")
   @Element
   private String y;
}

SimpleXML: Tutorial

This page provides a tutorial that will prepare users for using XML serialization. Before this tutorial is attempted it is advisable to have a look at the Javadoc documentation for the framework. Although there are only several annotations and objects involved in the serialization process the framework itself has many powerful features which this tutorial attempts to describe.

TypeScript Language Specification


Version 1.8 [[GitHub]](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md "Microsoft/TypeScript@GitHub")

January, 2016

Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement Version 1.0 (“OWF 1.0”) as of October 1, 2012. The OWF 1.0 is available at here.

TypeScript is a trademark of Microsoft Corporation.

客家习俗

客家人 的习俗大致上包括全国性的传统岁序节俗,地方性崇拜、礼节等。

主要节日

  • 春节:有拜年,游乐活动等,是最隆重的节日。
  • 立春:即交春。
  • 元宵节:正月十五是中国民间传统的元宵节。元宵节吃元宵,玩灯,赏灯,猜灯谜。
  • 二月二:开正节。
  • 清明:客家扫墓习俗多从春分开始,清明达到高潮。
  • 端午:客家普遍称为五月节。节日主要内容是吃粽子,雄黄酒,龙舟赛。
  • 七月节:也即鬼节。
  • 中秋:民间通称八月节。吃月饼,赏月等风俗大体各地相同。
  • 重阳节:客家人叫“九月节”。
  • 冬至:客家人有“冬大过年”之说。

电脑配置单

配置清单

  • CPU : AMD APU系列 A6-7400K 双核 R5核显 FM2+接口 盒装CPU处理器 【京东】
  • 主板 : 微星(MSI)A88XM-E45 V2 【京东】
  • 内存 : 金士顿(Kingston)DDR3 1600 4GB 台式机内存 【京东】
  • 硬盘 : 希捷(ST1000DM003) 1TB 7200转64M SATA3 台式机硬盘【京东】
  • 机箱 : 爱国者 魔武者D1 中塔机箱电源套装(标配250W电源/USB3.0)【京东】
  • 显示器 : AOC I2260SWD 21.5英寸IPS广视角炫彩硬屏LED背光显示器 【京东】
  • 键鼠套装 : 罗技(Logitech)MK120 键鼠套装 黑色 【京东】