[XML] Resource帮助类
/// <summary>
/// 类说明:Resources
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary> using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization; namespace DotNet.Utilities
{
/// <summary>
/// BUResourceManager
/// 资源管理器
/// </author>
/// </summary>
[XmlRoot("resources")]
public class Resources
{
private SortedList<String, String> indexs = new SortedList<String, String>(); [XmlElement("language")]
public string language = string.Empty;
[XmlElement("displayName")]
public string displayName = string.Empty;
[XmlElement("version")]
public string version = string.Empty;
[XmlElement("author")]
public string author = string.Empty;
[XmlElement("description")]
public string description = string.Empty;
[XmlElement("items", typeof(Items))]
public Items items; public void createIndex()
{
indexs.Clear();
if (items == null)
{
return;
}
indexs = new SortedList<String, String>(items.items.Length);
for (int i = ; i < items.items.Length; i++)
{
#if DEBUG
try
{
[i] indexs.Add(items.items.key, items.items.value);
}
catch
{
throw (new Exception(items.items.key + items.items.value));
}
#else
indexs.Add(items.items.key, items.items.value);
#endif
}
} public string Get(string key)
{
if (!indexs.ContainsKey(key))
{
return string.Empty;
}
return indexs[key];
} /// <summary>
/// JiRiGaLa 2007.05.02
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool Set(string key, string value)
{
if (!indexs.ContainsKey(key))
{
return false;
}
indexs[key] = value;
for (int i = ; i < items.items.Length; i++)
{
if (items.items.key == key)
{
items.items.value = value;
break;
}
}
return true;
}
} public class Items
{
[XmlElement("item", typeof(Item))]
public Item[] items;
} public class Item
{
[XmlAttribute("key")]
public string key = string.Empty;
[XmlText]
public string value = string.Empty;
} internal class ResourcesSerializer
{
public static Resources DeSerialize(string filePath)
{
System.Xml.Serialization.XmlSerializer XmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Resources));
System.IO.FileStream FileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
Resources Resources = XmlSerializer.Deserialize(FileStream) as Resources;
FileStream.Close();
return Resources;
} public static void Serialize(string filePath, Resources Resources)
{
System.Xml.Serialization.XmlSerializer XmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Resources));
System.IO.FileStream FileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
XmlSerializer.Serialize(FileStream, Resources);
FileStream.Close();
}
}
}
[XML] Resource帮助类的更多相关文章
- 8 -- 深入使用Spring -- 3...1 Resource实现类ServletContextResource
8.3.1 Resource实现类------ServletContextResource:访问相对于ServletContext路径下的资源的实现类. 4.访问应用相关资源 Spring提供了Ser ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类FileSystemResource
8.3.1 Resource实现类------FileSystemResource:访问文件系统的资源的实现类 3.访问文件系统资源 Spring提供的FileSystemResource类用于访问文 ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类ClassPathResource
8.3.1 Resource实现类------ClassPathResource : 访问类加载路径下的资源的实现类 2.访问类加载路径下的资源 ClassPathResource 用来访问类加载路径 ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类UrlResource
8.3.1 Resource 实现类------UrlResource : 访问网络资源的实现类 1.访问网络资源 访问网络资源通过UrlResource 类实现,UrlResource是java.n ...
- 阶段3 1.Mybatis_03.自定义Mybatis框架_4.自定义mybatis的编码-解析XML的工具类介绍
导入xml操作的类和用到的相关包 创建util包,然后把提供好的XMLConfigBuilder.java文件复制3过来 复制过来,里面用到了很多dom4j的东西 打开pom.xml 输入depend ...
- 让Visual Studio 2013为你自动生成XML反序列化的类
Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: 1. 在代码编辑界面的右侧滚动条上显示不同颜色的标签,让开发人员可以对所编辑文档的修改.查找.定位情 ...
- XML格式示例 与 XML操作(读取)类封装
header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...
- c# XML和实体类之间相互转换(序列化和反序列化)[砖]
link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...
- C# XML和实体类之间相互转换(序列化和反序列化)
我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...
随机推荐
- 点分治练习:不虚就是要AK
[题面] 不虚就是要AK(czyak.c/.cpp/.pas) 2s 128M czy很火.因为又有人说他虚了.为了证明他不虚,他决定要在这次比赛AK. 现在他正在和别人玩一个游戏:在一棵树上随机取两 ...
- HDU 4786 Fibonacci Tree (2013成都1006题) 最小生成树+斐波那契
题意:问生成树里能不能有符合菲波那切数的白边数量 思路:白边 黑边各优先排序求最小生成树,并统计白边在两种情况下数目,最后判断这个区间就可以.注意最初不连通就不行. #include <stdi ...
- HDU 4714 Tree2cycle DP 2013杭电热身赛 1009
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 Tree2cycle Time Limit: 15000/8000 MS (Java/Other ...
- yii 权限分级式访问控制的实现(非RBAC法)——已验证
验证和授权——官方文档: http://www.yiichina.com/guide/topics.auth http://www.yiiframework.com/doc/guide/1.1/zh_ ...
- pom.xml第一行报错
错误:Cannot detect Web Project version. Please specify version of Web Project through <version> ...
- Spring技术内幕——深入解析Spring架构与设计原理(一)IOC实现原理
IOC的基础 下面我们从IOC/AOP开始,它们是Spring平台实现的核心部分:虽然,我们一开始大多只是在这个层面上,做一些配置和外部特性的使用工作,但对这两个核心模块工作原理和运作机制的理解,对深 ...
- HTML5 简单画图,切片,变形
本人是在校学生,由于这段时间不知道怎么回事,心情比较无聊没有事干,所以利用这段时间学一下HTML5,发博客的目的是为了以后可以查询,也希望各位大神能够指导像我们这样的菜鸟,告别菜鸟的时段 我学东西时候 ...
- 王灏:光音网络致力打造Wi-Fi大生态圈
光音网络,做的是本地网络综合服务.在中国,想把互联网做到覆盖延伸范围之外的最后100米,光音网络是当中一家,也是最坚持的一家.为千万家本地生活商户提供帮助,为数亿本地用户提供最佳的本地网络体验,这是光 ...
- [Usaco2006 Nov]Corn Fields牧场的安排 壮压DP
看到第一眼就发觉是壮压DP 然后就三进制枚举子集吧. 这题真是壮压入门好题... 对于dp[i][j] 表示第i行,j状态下前i行的分配方案数. 那么dp[i][j]肯定是从i-1行转过来的 那么由于 ...
- android80 HttpClient框架提交数据 get方式
package com.itheima.httpclient; import java.io.IOException; import java.io.InputStream; import java. ...