您的位置:首页 > 其它

泛型实现不同类型的数据生成XML文件

2010-04-04 15:48 381 查看
除了配置文件外,很多时候我们需要使用到XML文档,并对其作一系列的操作。以下记录自己使用的一个小点,即将不同类型的数据生成对应的xml文档,使用时将其读出。仅适用初级人士,菜鸟级水平,请各大鸟手下留情。

首先定义一个类,实现两个方法,分别为写XML和读XML,注意类定义使泛型的使用。

代码如下:

代码

<?xml version="1.0" encoding="gb2312"?>
<ArrayOfTempClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<tempClass>
<id>0</id>
<str1>你好0</str1>
<str2>0Hello!</str2>
<str3>2010-4-4 15:52:54</str3>
</tempClass>
<tempClass>
<id>1</id>
<str1>你好1</str1>
<str2>1Hello!</str2>
<str3>2010-4-4 15:52:54</str3>
</tempClass>
<tempClass>
<id>2</id>
<str1>你好2</str1>
<str2>2Hello!</str2>
<str3>2010-4-4 15:52:54</str3>
</tempClass>
<tempClass>
<id>3</id>
<str1>你好3</str1>
<str2>3Hello!</str2>
<str3>2010-4-4 15:52:54</str3>
</tempClass>
<tempClass>
<id>4</id>
<str1>你好4</str1>
<str2>4Hello!</str2>
<str3>2010-4-4 15:52:54</str3>
</tempClass>
</ArrayOfTempClass>


示例完毕。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐