| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
fmms
13年前发布

xStream完美转换XML、JSON

     <p><b>xStream</b><b>框架</b> </p>    <p>xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换; </p>    <p>前面有介绍过json-lib这个框架,在线博文:<a href="http://www.open-open.com/lib/view/open1327991992093.html" target="_blank">http://www.open-open.com/lib/view/open1327991992093.html</a> </p>    <p>以及Jackson这个框架,在线博文:<a href="http://www.open-open.com/lib/view/open1327992553405.html" target="_blank">http://www.open-open.com/lib/view/open1327992553405.html</a> </p>    <p>它们都完美支持JSON,但是对xml的支持还不是很好。一定程度上限制了对Java对象的描述,不能让xml完全体现到对Java对象的描述。这里将会介绍xStream对JSON、XML的完美支持。xStream不仅对XML的转换非常友好,而且提供annotation注解,可以在JavaBean 中完成对xml节点、属性的描述。以及对JSON也支持,只需要提供相关的JSONDriver就可以完成转换。 </p>    <p><b>一、</b><b>准备工作</b> </p>    <p>1、 下载jar包、及官方资源 </p>    <p>xStream的jar下载地址: </p>    <p><a href="/misc/goto?guid=4959517674913439055">https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-distribution/1.3.1/xstream-distribution-1.3.1-bin.zip</a> </p>    <p>官方的示例很全,官方参考示例:<a href="/misc/goto?guid=4959517674997161594">http://xstream.codehaus.org/tutorial.html</a> </p>    <p>添加xstream-1.3.1.jar文件到工程中,就可以开始下面的工作;需要的jar如下: </p>    <p><a href="https://simg.open-open.com/show/7a90938963c50cc58da1504d621c429c.jpg"><img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image002" border="0" alt="clip_image002" src="https://simg.open-open.com/show/98568adef25e420d10fa0b4303b96af8.jpg" width="143" height="77" /></a> </p>    <p>2、 测试用例代码 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.test;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.IOException;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.ObjectInputStream;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.ObjectOutputStream;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.StringReader;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.Writer;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.ArrayList;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.HashMap;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Iterator;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.List;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Map;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Set;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.codehaus.jettison.json.JSONException;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.After;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Before;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Test;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.Birthday;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.Classes;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.ListBean;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.Student;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.XStream;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.io.HierarchicalStreamWriter;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.io.json.JsonWriter;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>Java对象和XML字符串的相互转换</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * jar-lib-version: xstream-1.3.1</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 12:15:15 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @file XStreamTest.java</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @package com.hoo.test</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @project WebHttpUtils</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @blog http://blog.csdn.net/IBM_hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @email hoojo_@126.com</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @version 1.0</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@SuppressWarnings(<span style="color:#006080;">"unchecked"</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> XStreamTest {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> XStream xstream = null;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> ObjectOutputStream  out = null;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> ObjectInputStream in = null;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> Student bean = null;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * <b>function:</b>初始化资源准备</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * @createDate Nov 27, 2010 12:16:28 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @Before</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> init() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            xstream = <span style="color:#0000ff;">new</span> XStream();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#008000;">//xstream = new XStream(new DomDriver()); // 需要xpp3 jar</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setAddress(<span style="color:#006080;">"china"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setEmail(<span style="color:#006080;">"jack@email.com"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setId(1);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Birthday day = <span style="color:#0000ff;">new</span> Birthday();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        day.setBirthday(<span style="color:#006080;">"2010-11-22"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setBirthday(day);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * <b>function:</b>释放对象资源</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * @createDate Nov 27, 2010 12:16:38 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @After</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> destory() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream = null;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = null;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">if</span> (out != null) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                out.flush();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                out.close();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">if</span> (in != null) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                in.close();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        } <span style="color:#0000ff;">catch</span> (IOException e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.gc();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">void</span> fail(String string) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(string);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">void</span> failRed(String string) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.err.println(string);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>通过XStream对象的toXML方法就可以完成Java对象到XML的转换,toXML方法还有2个相同签名的方法,需要传递一个流。然后通过流来完成xml信息的输出。 </p>    <p>3、 需要的JavaBean </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Student {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> id;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String name;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String email;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String address;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> Birthday birthday;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//getter、setter</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> String toString() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.name + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.id + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.address + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.birthday + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.email;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p></p>    <p><b>二、</b><b>Java</b><b>转换成</b><b>XML</b> </p>    <p>1、 JavaBean转换XM </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>Java对象转换成XML字符串</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 12:19:01 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeBean2XML() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"------------Bean->XML------------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(xstream.toXML(bean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"重命名后的XML"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//类重命名</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.alias("account", Student.class);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.alias("生日", Birthday.class);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.aliasField("生日", Student.class, "birthday");</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.aliasField("生日", Birthday.class, "birthday");</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//fail(xstream.toXML(bean));</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//属性重命名</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.aliasField(<span style="color:#006080;">"邮件"</span>, Student.<span style="color:#0000ff;">class</span>, <span style="color:#006080;">"email"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//包重命名</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.aliasPackage(<span style="color:#006080;">"hoo"</span>, <span style="color:#006080;">"com.hoo.entity"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(xstream.toXML(bean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>看结果中的第一份xml内容,是没有经过然后修改或重命名的文档,按照原样输出。文档中的第二份文档的package经过重命名,email属性也经过重命名以及类名也可以进行重命名的。 </p>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">------------Bean-<span style="color:#006080;">></span>XML------------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Student</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>1<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>jack@email<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span>2010-11-22<span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Student</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">重命名后的XML</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>hoo<span style="color:#cc6633;">.Student</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>1<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>邮件<span style="color:#006080;">></span>jack@email<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/邮件<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span>2010-11-22<span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/hoo<span style="color:#cc6633;">.Student</span><span style="color:#006080;">></span></pre>     </div>    </div>    <p>2、 将List集合转换成xml文档 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>将Java的List集合转换成XML对象</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 12:20:07 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeList2XML() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//修改元素名称</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.alias(<span style="color:#006080;">"beans"</span>, ListBean.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"----------List-->XML----------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        ListBean listBean = <span style="color:#0000ff;">new</span> ListBean();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        listBean.setName(<span style="color:#006080;">"this is a List Collection"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        List<Object> list = <span style="color:#0000ff;">new</span> ArrayList<Object>();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list.add(bean);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list.add(bean);<span style="color:#008000;">//引用bean</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//list.add(listBean);//引用listBean,父元素</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setAddress(<span style="color:#006080;">"china"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setEmail(<span style="color:#006080;">"tom@125.com"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setId(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"tom"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Birthday day = <span style="color:#0000ff;">new</span> Birthday(<span style="color:#006080;">"2010-11-22"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setBirthday(day);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list.add(bean);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        listBean.setList(list);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//将ListBean中的集合设置空元素,即不显示集合元素标签</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.addImplicitCollection(ListBean.class, "list");</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//设置reference模型</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.setMode(XStream.NO_REFERENCES);//不引用</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.setMode(XStream.ID_REFERENCES);<span style="color:#008000;">//id引用</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);//绝对路径引用</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//将name设置为父类(Student)的元素的属性</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.useAttributeFor(Student.<span style="color:#0000ff;">class</span>, <span style="color:#006080;">"name"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.useAttributeFor(Birthday.<span style="color:#0000ff;">class</span>, <span style="color:#006080;">"birthday"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//修改属性的name</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.aliasAttribute(<span style="color:#006080;">"姓名"</span>, <span style="color:#006080;">"name"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.aliasField(<span style="color:#006080;">"生日"</span>, Birthday.<span style="color:#0000ff;">class</span>, <span style="color:#006080;">"birthday"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(xstream.toXML(listBean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>上面的代码运行后,结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">----------List--<span style="color:#006080;">></span>XML----------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>beans id="1"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>this is a List Collection<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>list id="2"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>student id="3" 姓名="jack"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>1<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>jack@email<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>birthday id="4" 生日="2010-11-22"/<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>student reference="3"/<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>student id="5" 姓名="tom"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>2<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>tom@125<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>birthday id="6" 生日="2010-11-22"/<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/list<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/beans<span style="color:#006080;">></span></pre>     </div>    </div>    <p>如果不加xstream.addImplicitCollection(ListBean.<b>class</b>, "list"); </p>    <p>这个设置的话,会出现一个List节点包裹着Student节点元素。添加addImplicitCollection可以忽略这个list节点元素。那么上面的list节点就不存在,只会在beans元素中出现name、student这2个xml元素标签; </p>    <p>setMode是设置相同的对象的引用方式,如果设置XStream.NO_REFERENCES就是不引用,会输出2分相同的 Student元素。如果是XStream.ID_REFERENCES会引用相同的那个对象的id属性,如果是 XStream.XPATH_ABSOLUTE_REFERENCES引用,那么它将显示xpath路径。上面采用的id引用,<student reference="3"/>这个引用了id=3的那个student标签元素; </p>    <p>useAttributeFor是设置某个节点显示到父节点的属性中,也就是将指定class中的指定属性,在这个class元素节点的属性中显示。 </p>    <p>如:<student><name>hoojo</name></student> </p>    <p>设置好后就是这样的结果:<student name=”hoojo”></student> </p>    <p>aliasAttribute是修改属性名称。 </p>    <p>3、 在JavaBean中添加Annotation注解进行重命名设置 </p>    <p>先看看JavaBean的代码 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Arrays;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Calendar;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.GregorianCalendar;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.List;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.annotations.XStreamAlias;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.annotations.XStreamAsAttribute;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.annotations.XStreamConverter;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.annotations.XStreamImplicit;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.annotations.XStreamOmitField;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@XStreamAlias(<span style="color:#006080;">"class"</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Classes {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">/*</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * 设置属性显示</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @XStreamAsAttribute</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @XStreamAlias(<span style="color:#006080;">"名称"</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> String name;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">/*</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     * 忽略</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">     */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @XStreamOmitField</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> number;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @XStreamImplicit(itemFieldName = <span style="color:#006080;">"Students"</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> List<Student> students;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @SuppressWarnings(<span style="color:#006080;">"unused"</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    @XStreamConverter(SingleValueCalendarConverter.<span style="color:#0000ff;">class</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">private</span> Calendar created = <span style="color:#0000ff;">new</span> GregorianCalendar();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> Classes(){}</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">public</span> Classes(String name, Student... stu) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">this</span>.name = name;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">this</span>.students = Arrays.asList(stu);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//getter、setter</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>SingleValueCalendarConverter.java这个是一个类型转换器 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Calendar;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Date;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.GregorianCalendar;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.converters.Converter;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.converters.MarshallingContext;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.converters.UnmarshallingContext;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.io.HierarchicalStreamReader;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.thoughtworks.xstream.io.HierarchicalStreamWriter;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> SingleValueCalendarConverter <span style="color:#0000ff;">implements</span> Converter {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> marshal(Object source, HierarchicalStreamWriter writer,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                MarshallingContext context) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            Calendar calendar = (Calendar) source;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            writer.setValue(String.valueOf(calendar.getTime().getTime()));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> Object unmarshal(HierarchicalStreamReader reader,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">                UnmarshallingContext context) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            GregorianCalendar calendar = <span style="color:#0000ff;">new</span> GregorianCalendar();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            calendar.setTime(<span style="color:#0000ff;">new</span> Date(Long.parseLong(reader.getValue())));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> calendar;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        @SuppressWarnings(<span style="color:#006080;">"unchecked"</span>)</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">boolean</span> canConvert(Class type) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> type.equals(GregorianCalendar.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>再看看测试用例代码 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeList2XML4Annotation() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"---------annotation Bean --> XML---------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Student stu = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        stu.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Classes c = <span style="color:#0000ff;">new</span> Classes(<span style="color:#006080;">"一班"</span>, bean, stu);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        c.setNumber(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//对指定的类使用Annotation</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.processAnnotations(Classes.class);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//启用Annotation</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#008000;">//xstream.autodetectAnnotations(true);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(xstream.toXML(c));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>当启用annotation或是对某个特定的类启用annotation时,上面的classes这个类才有效果。如果不启用annotation,运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">---------annotation Bean --<span style="color:#006080;">></span> XML---------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Classes</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>一班<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>number<span style="color:#006080;">></span>2<span style="color:#006080;"><</span>/number<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>students class="java<span style="color:#cc6633;">.util</span><span style="color:#cc6633;">.Arrays</span>$ArrayList"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>a class="student-array"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>1<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>jack@email<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span>2010-11-22<span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>0<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/a<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/students<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>created<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>time<span style="color:#006080;">></span>1303292056718<span style="color:#006080;"><</span>/time<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>timezone<span style="color:#006080;">></span>Asia/Shanghai<span style="color:#006080;"><</span>/timezone<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/created<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Classes</span><span style="color:#006080;">></span></pre>     </div>    </div>    <p>当启用annotation后xstream.processAnnotations(Classes.class),结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">---------annotation Bean --<span style="color:#006080;">></span> XML---------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>class 名称="一班"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>Students<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>1<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>jack@email<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span>2010-11-22<span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/Students<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>Students<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>0<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/Students<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>created<span style="color:#006080;">></span>1303292242937<span style="color:#006080;"><</span>/created<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/class<span style="color:#006080;">></span></pre>     </div>    </div>    <p>4、 Map集合转换xml文档 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>Java Map集合转XML</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 1:13:26 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeMap2XML() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"---------Map --> XML---------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Map<String, Student> map = <span style="color:#0000ff;">new</span> HashMap<String, Student>();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        map.put(<span style="color:#006080;">"No.1"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setAddress(<span style="color:#006080;">"china"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setEmail(<span style="color:#006080;">"tom@125.com"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setId(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"tom"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Birthday day = <span style="color:#0000ff;">new</span> Birthday(<span style="color:#006080;">"2010-11-22"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setBirthday(day);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        map.put(<span style="color:#006080;">"No.2"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        map.put(<span style="color:#006080;">"No.3"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.alias(<span style="color:#006080;">"key"</span>, String.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.useAttributeFor(Student.<span style="color:#0000ff;">class</span>, <span style="color:#006080;">"id"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        xstream.useAttributeFor(<span style="color:#006080;">"birthday"</span>, String.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(xstream.toXML(map));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">---------Map --<span style="color:#006080;">></span> XML---------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span><span style="color:#0000ff;">map</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>entry<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>key<span style="color:#006080;">></span>No.3<span style="color:#006080;"><</span>/key<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>student id="0"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/entry<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>entry<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>key<span style="color:#006080;">></span>No.1<span style="color:#006080;"><</span>/key<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>student id="1"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>jack@email<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>birthday birthday="2010-11-22"/<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/entry<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>entry<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>key<span style="color:#006080;">></span>No.2<span style="color:#006080;"><</span>/key<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>student id="2"<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>tom<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>email<span style="color:#006080;">></span>tom@125<span style="color:#cc6633;">.com</span><span style="color:#006080;"><</span>/email<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span><span style="color:#0000ff;">address</span><span style="color:#006080;">></span>china<span style="color:#006080;"><</span>/<span style="color:#0000ff;">address</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;"><</span>birthday birthday="2010-11-22"/<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>/student<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/entry<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/<span style="color:#0000ff;">map</span><span style="color:#006080;">></span></pre>     </div>    </div>    <p>5、 用OutStream输出流写XML </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>用OutStream输出流写XML</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 1:13:48 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeXML4OutStream() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out = xstream.createObjectOutputStream(System.out);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Student stu = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        stu.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Classes c = <span style="color:#0000ff;">new</span> Classes(<span style="color:#006080;">"一班"</span>, bean, stu);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        c.setNumber(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"---------ObjectOutputStream # JavaObject--> XML---------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out.writeObject(stu);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out.writeObject(<span style="color:#0000ff;">new</span> Birthday(<span style="color:#006080;">"2010-05-33"</span>));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out.write(22);<span style="color:#008000;">//byte</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out.writeBoolean(true);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out.writeFloat(22.f);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        out.writeUTF(<span style="color:#006080;">"hello"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>使用输出流后,可以通过流对象完成xml的构建,即使没有JavaBean对象,你可以用流来构建一个复杂的xml文档,运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">---------ObjectOutputStream # JavaObject--<span style="color:#006080;">></span> XML---------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span><span style="color:#0000ff;">object</span>-stream<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Student</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>id<span style="color:#006080;">></span>0<span style="color:#006080;"><</span>/id<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>name<span style="color:#006080;">></span>jack<span style="color:#006080;"><</span>/name<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Student</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Birthday</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;"><</span>birthday<span style="color:#006080;">></span>2010-05-33<span style="color:#006080;"><</span>/birthday<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>/com<span style="color:#cc6633;">.hoo</span><span style="color:#cc6633;">.entity</span><span style="color:#cc6633;">.Birthday</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>byte<span style="color:#006080;">></span>22<span style="color:#006080;"><</span>/byte<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>boolean<span style="color:#006080;">></span>true<span style="color:#006080;"><</span>/boolean<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span><span style="color:#0000ff;">float</span><span style="color:#006080;">></span>22.0<span style="color:#006080;"><</span>/<span style="color:#0000ff;">float</span><span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;"><</span>string<span style="color:#006080;">></span>hello<span style="color:#006080;"><</span>/string<span style="color:#006080;">></span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#006080;"><</span>/<span style="color:#0000ff;">object</span>-stream<span style="color:#006080;">></span></pre>     </div>    </div>    <p></p>    <p><b>三、</b><b>XML</b><b>内容转换</b><b>Java</b><b>对象</b> </p>    <p>1、 用InputStream将XML文档转换成java对象 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>用InputStream将XML文档转换成java对象 </span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 需要额外的jar xpp3-main.jar</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 1:14:52 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readXML4InputStream() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        String s = <span style="color:#006080;">"<object-stream><com.hoo.entity.Student><id>0</id><name>jack</name>"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"</com.hoo.entity.Student><com.hoo.entity.Birthday><birthday>2010-05-33</birthday>"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"</com.hoo.entity.Birthday><byte>22</byte><boolean>true</boolean><float>22.0</float>"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"<string>hello</string></object-stream>"</span>;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"---------ObjectInputStream## XML --> javaObject---------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        StringReader reader = <span style="color:#0000ff;">new</span> StringReader(s);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        in = xstream.createObjectInputStream(reader);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Student stu = (Student) in.readObject();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Birthday b = (Birthday) in.readObject();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">byte</span> i = in.readByte();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">boolean</span> bo = in.readBoolean();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">float</span> f = in.readFloat();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        String str = in.readUTF();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(stu);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(b);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(i);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(bo);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(f);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        System.out.println(str);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>读取后,转换的Java对象,结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">---------ObjectInputStream## XML --> javaObject---------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">jack#0#null#null#null</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">2010-05-33</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">22</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">true</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">22.0</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">hello</pre>     </div>    </div>    <p>2、 将xml文档转换成Java对象 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>将XML字符串转换成Java对象</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 2:39:06 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readXml2Object() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#0000ff;">try</span> {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"-----------Xml >>> Bean--------------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Student stu = (Student) xstream.fromXML(xstream.toXML(bean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(stu.toString());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        List<Student> list = <span style="color:#0000ff;">new</span> ArrayList<Student>();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list.add(bean);<span style="color:#008000;">//add</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Map<String, Student> map = <span style="color:#0000ff;">new</span> HashMap<String, Student>();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        map.put(<span style="color:#006080;">"No.1"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setAddress(<span style="color:#006080;">"china"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setEmail(<span style="color:#006080;">"tom@125.com"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setId(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"tom"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Birthday day = <span style="color:#0000ff;">new</span> Birthday(<span style="color:#006080;">"2010-11-22"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setBirthday(day);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list.add(bean);<span style="color:#008000;">//add</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        map.put(<span style="color:#006080;">"No.2"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        bean.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        list.add(bean);<span style="color:#008000;">//add</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        map.put(<span style="color:#006080;">"No.3"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"==========XML >>> List==========="</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        List<Student> studetns = (List<Student>) xstream.fromXML(xstream.toXML(list));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"size:"</span> + studetns.size());<span style="color:#008000;">//3</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">for</span> (Student s : studetns) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            fail(s.toString());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        failRed(<span style="color:#006080;">"==========XML >>> Map==========="</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Map<String, Student> maps = (Map<String, Student>) xstream.fromXML(xstream.toXML(map));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        fail(<span style="color:#006080;">"size:"</span> + maps.size());<span style="color:#008000;">//3</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Set<String> key = maps.keySet();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        Iterator<String> iter = key.iterator();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">while</span> (iter.hasNext()) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            String k = iter.next();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            fail(k + <span style="color:#006080;">":"</span> + map.get(k));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    } <span style="color:#0000ff;">catch</span> (Exception e) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        e.printStackTrace();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">-----------Xml >>> Bean--------------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">jack#1#china#2010-11-22#jack@email.com</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==========XML >>> List===========</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">size:3</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">jack#1#china#2010-11-22#jack@email.com</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">tom#2#china#2010-11-22#tom@125.com</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">jack#0#null#null#null</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">==========XML >>> Map===========</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">size:3</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">No.3:jack#0#null#null#null</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">No.1:jack#1#china#2010-11-22#jack@email.com</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">No.2:tom#2#china#2010-11-22#tom@125.com</pre>     </div>    </div>    <p>怎么样,成功的完成XML到JavaBean、List、Map的转换,更多对象转换还需要大家一一尝试。用法类似~这里就不一样赘述。 </p>    <p><b>四、</b><b>XStream</b><b>对</b><b>JSON</b><b>的支持</b> </p>    <p>xStream对JSON也有非常好的支持,它提供了2个模型驱动。用这2个驱动可以完成Java对象到JSON的相互转换。使用JettisonMappedXmlDriver驱动,将Java对象转换成json,需要添加jettison.jar </p>    <p>1、 用JettisonMappedXmlDriver完成Java对象到JSON的转换 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>XStream结合JettisonMappedXmlDriver驱动,转换Java对象到JSON</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 需要添加jettison jar</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 1:23:18 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeEntity2JETTSON() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    failRed(<span style="color:#006080;">"=======JettisonMappedXmlDriver===JavaObject >>>> JaonString========="</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JettisonMappedXmlDriver());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.setMode(XStream.NO_REFERENCES);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(bean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">=======JettisonMappedXmlDriver===JavaObject >>>> JaonString=========</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"student"</span>:{<span style="color:#006080;">"id"</span>:1,<span style="color:#006080;">"name"</span>:<span style="color:#006080;">"jack"</span>,<span style="color:#006080;">"email"</span>:<span style="color:#006080;">"jack@email.com"</span>,<span style="color:#006080;">"address"</span>:<span style="color:#006080;">"china"</span>,<span style="color:#006080;">"birthday"</span>:[{},<span style="color:#006080;">"2010-11-22"</span>]}}</pre>     </div>    </div>    <p>JSON的转换和XML的转换用法一样,只是创建XStream需要传递一个参数,这个参数就是xml到JSON映射转换的驱动。这里会降到两个驱动,分别是JettisonMappedXmlDriver、JsonHierarchicalStreamDriver。 </p>    <p>2、 JsonHierarchicalStreamDriver完成Java对象到JSON的转换 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>用XStream结合JsonHierarchicalStreamDriver驱动</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 转换java对象为JSON字符串</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 1:16:46 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeEntiry2JSON() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    failRed(<span style="color:#006080;">"======JsonHierarchicalStreamDriver====JavaObject >>>> JaonString========="</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JsonHierarchicalStreamDriver());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//xstream.setMode(XStream.NO_REFERENCES);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    failRed(<span style="color:#006080;">"-------Object >>>> JSON---------"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(bean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//failRed("========JsonHierarchicalStreamDriver==删除根节点=========");</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//删除根节点</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JsonHierarchicalStreamDriver() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> HierarchicalStreamWriter createWriter(Writer out) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> JsonWriter(out, JsonWriter.DROP_ROOT_MODE);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    });</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//xstream.setMode(XStream.NO_REFERENCES);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(bean));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">======JsonHierarchicalStreamDriver====JavaObject >>>> JaonString=========</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">-------Object >>>> JSON---------</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"student"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"id"</span>: 1,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"jack@email.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}}</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"id"</span>: 1,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"jack@email.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>使用JsonHierarchicalStreamDriver转换默认会给转换后的对象添加一个根节点,但是在构建JsonHierarchicalStreamDriver驱动的时候,你可以重写createWriter方法,删掉根节点。 </p>    <p>看上面的结果,一个是默认带根节点的JSON对象,它只是将类名作为一个属性,将对象作为该属性的一个值。而另一个没有带根属性的JSON就是通过重写createWriter方法完成的。 </p>    <p>3、 将List集合转换成JSON字符串 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeList2JSON() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    failRed(<span style="color:#006080;">"======JsonHierarchicalStreamDriver====JavaObject >>>> JaonString========="</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    JsonHierarchicalStreamDriver driver = <span style="color:#0000ff;">new</span> JsonHierarchicalStreamDriver();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(driver);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//xstream = new XStream(new JettisonMappedXmlDriver());//转换错误</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//xstream.setMode(XStream.NO_REFERENCES);</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    List<Student> list = <span style="color:#0000ff;">new</span> ArrayList<Student>();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    list.add(bean);<span style="color:#008000;">//add</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setAddress(<span style="color:#006080;">"china"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setEmail(<span style="color:#006080;">"tom@125.com"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setId(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setName(<span style="color:#006080;">"tom"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Birthday day = <span style="color:#0000ff;">new</span> Birthday(<span style="color:#006080;">"2010-11-22"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setBirthday(day);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    list.add(bean);<span style="color:#008000;">//add</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    list.add(bean);<span style="color:#008000;">//add</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(list));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//failRed("========JsonHierarchicalStreamDriver==删除根节点=========");</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//删除根节点</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JsonHierarchicalStreamDriver() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> HierarchicalStreamWriter createWriter(Writer out) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> JsonWriter(out, JsonWriter.DROP_ROOT_MODE);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    });</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(list));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">======JsonHierarchicalStreamDriver====JavaObject >>>> JaonString=========</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">##{<span style="color:#006080;">"list"</span>: [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"id"</span>: 1,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"jack@email.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  },</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"id"</span>: 2,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"tom"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"tom@125.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  },</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"id"</span>: 0,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">]}</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">#[</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"id"</span>: 1,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"jack@email.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  },</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"id"</span>: 2,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"tom"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"tom@125.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  },</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"id"</span>: 0,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">]</pre>     </div>    </div>    <p>上面的list1是使用JsonHierarchicalStreamDriver 转换的,当然你也可以使用JettisonMappedXmlDriver驱动进行转换;用JettisonMappedXmlDriver转换后,你会发现格式不同而且没有根属性。 </p>    <p>4、 Map转换json </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> writeMap2JSON() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    failRed(<span style="color:#006080;">"======JsonHierarchicalStreamDriver==== Map >>>> JaonString========="</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JsonHierarchicalStreamDriver());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//xstream = new XStream(new JettisonMappedXmlDriver());</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    Map<String, Student> map = <span style="color:#0000ff;">new</span> HashMap<String, Student>();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"No.1"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setAddress(<span style="color:#006080;">"china"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setEmail(<span style="color:#006080;">"tom@125.com"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setId(2);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setName(<span style="color:#006080;">"tom"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setBirthday(<span style="color:#0000ff;">new</span> Birthday(<span style="color:#006080;">"2010-11-21"</span>));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"No.2"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean = <span style="color:#0000ff;">new</span> Student();</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    bean.setName(<span style="color:#006080;">"jack"</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    map.put(<span style="color:#006080;">"No.3"</span>, bean);<span style="color:#008000;">//put</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(map));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//failRed("========JsonHierarchicalStreamDriver==删除根节点=========");</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//删除根节点</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JsonHierarchicalStreamDriver() {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#0000ff;">public</span> HierarchicalStreamWriter createWriter(Writer out) {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> JsonWriter(out, JsonWriter.DROP_ROOT_MODE);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    });</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.toXML(map));</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">======JsonHierarchicalStreamDriver==== Map >>>> JaonString=========</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"map"</span>: [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"No.3"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"id"</span>: 0,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  ],</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"No.1"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"id"</span>: 1,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"jack@email.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  ],</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"No.2"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"id"</span>: 2,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"tom"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"tom@125.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-21"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  ]</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">]}</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">[</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"No.3"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"id"</span>: 0,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  ],</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"No.1"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"id"</span>: 1,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"jack"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"jack@email.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  ],</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  [</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"No.2"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"id"</span>: 2,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"name"</span>: <span style="color:#006080;">"tom"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"email"</span>: <span style="color:#006080;">"tom@125.com"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      <span style="color:#006080;">"birthday"</span>: {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-21"</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">      }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    }</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">  ]</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">]</pre>     </div>    </div>    <p>5、 将JSON转换java对象 </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>JsonHierarchicalStreamDriver可以将简单的json字符串转换成java对象,list、map转换不成功;</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * JsonHierarchicalStreamDriver读取JSON字符串到java对象出错</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate Nov 27, 2010 1:22:26 PM</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @throws JSONException</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> readJSON2Object() <span style="color:#0000ff;">throws</span> JSONException {</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    String json = <span style="color:#006080;">"{\"student\": {"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"id\": 1,"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"name\": \"haha\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"email\": \"email\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"address\": \"address\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"\"birthday\": {"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"birthday\": \"2010-11-22\""</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">        <span style="color:#006080;">"}"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#006080;">"}}"</span>;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//JsonHierarchicalStreamDriver读取JSON字符串到java对象出错,但JettisonMappedXmlDriver可以</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream = <span style="color:#0000ff;">new</span> XStream(<span style="color:#0000ff;">new</span> JettisonMappedXmlDriver());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    xstream.alias(<span style="color:#006080;">"student"</span>, Student.<span style="color:#0000ff;">class</span>);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    fail(xstream.fromXML(json).toString());</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    </pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//JettisonMappedXmlDriver转换List集合出错,但JsonHierarchicalStreamDriver可以转换正确</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    <span style="color:#008000;">//JettisonMappedXmlDriver 转换的字符串 {"list":{"student":[{"id":1,"name":"haha","email":"email","address":"address","birthday":[{},"2010-11-22"]}]},"student":{"id":2,"name":"tom","email":"tom@125.com","address":"china","birthday":[{},"2010-11-22"]}}</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    json = <span style="color:#006080;">"{\"list\": [{"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"id\": 1,"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"name\": \"haha\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"email\": \"email\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"address\": \"address\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"birthday\": {"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">              <span style="color:#006080;">"\"birthday\": \"2010-11-22\""</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"}"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">           <span style="color:#006080;">"},{"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"id\": 2,"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"name\": \"tom\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"email\": \"tom@125.com\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"address\": \"china\","</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"\"birthday\": {"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">              <span style="color:#006080;">"\"birthday\": \"2010-11-22\""</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">            <span style="color:#006080;">"}"</span> +</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">          <span style="color:#006080;">"}]}"</span>;</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(json);<span style="color:#008000;">//用js转换成功</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    List list = (List) xstream.fromXML(json);</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">    System.out.println(list.size());<span style="color:#008000;">//0好像转换失败</span></pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>     </div>    </div>    <p>运行后结果如下: </p>    <div id="codeSnippetWrapper">     <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet">      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">haha#1#address#2010-11-22#email</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"list"</span>: [{<span style="color:#006080;">"id"</span>: 1,<span style="color:#006080;">"name"</span>: <span style="color:#006080;">"haha"</span>,<span style="color:#006080;">"email"</span>: <span style="color:#006080;">"email"</span>,<span style="color:#006080;">"address"</span>: <span style="color:#006080;">"address"</span>,<span style="color:#006080;">"birthday"</span>: {<span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span>}},</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">{<span style="color:#006080;">"id"</span>: 2,<span style="color:#006080;">"name"</span>: <span style="color:#006080;">"tom"</span>,<span style="color:#006080;">"email"</span>: <span style="color:#006080;">"tom@125.com"</span>,<span style="color:#006080;">"address"</span>: <span style="color:#006080;">"china"</span>,<span style="color:#006080;">"birthday"</span>: {<span style="color:#006080;">"birthday"</span>: <span style="color:#006080;">"2010-11-22"</span>}}]}</pre>      <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">0</pre>     </div>    </div>    <p>JSON到Java的转换是fromXML方法。<br /> <br /> 来自:<a href="/misc/goto?guid=4959517675097234099" target="_blank">http://www.cnblogs.com/hoojo/archive/2011/04/22/2025197.html</a></p>     
 本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1327992749468.html
JSON JSON开发包