摘要:
using system;
using system.componentmodel;
using system.data;
using system.xml;
namespace system.data.xmlclient
{
public class xmlcommand : component, idbcommand, icloneable
{
// construc......
摘要:
using system;
using system.componentmodel;
using system.data;
using system.xml;
namespace system.data.xmlclient
{
public class xmlconnection : component, idbconnection, icloneable
{
// co......
.NET使XML串行化易如反掌
人们一直高喊xml是解决系统互联问题的关键, 而.net framework 也为处理xml数据提供了许多不同的类库. xmldocument 类能让你像处理文件一样处理xml 数据, 而xmlreader, xmlwriter, 与它们的派生类使你能够将xml 数据做为数据流处理. xmlserializer 则提供了另外的方法, 它使你能够将自己的对象串行与反串行化为xml. 串行化数据既能够让你像处理文件一样对数据进行随机存取, 同时又能够跳过你不感兴趣的元素. 在本文中, 我将向你展示如何使用xmlserializer类以及如何在你的类中添加属性来控制串行化过程.
xmlserializer
xmlserializer类存在于system.xml.serialization命名空间的system.xml.dll中, 它用一种高度松散耦合的方式提供串行化服务. 你的类不需要继承特别的基类, 而且它们也不需要实现任何特别的接口. 相反的, 你只需要在你的类或者这些类的公共域以及读/写属性里加上自定义的属性. xmlserializer 通过相反映射读取这些属性并用它们将你的类与类成员映射到xml元素与属性.
将xml 映射到对象
考虑表a中的xml语句, 哪一个正确的描述了一家电影院中上映的电影呢?
表a
<?xml version="1.0" encoding="utf-8" ?>
<theater>
<name>the camelot</name>
<phone>(888)665-2222</phone>
<movie minutes="120" stars="2">
<title>the score</title>
<rating>r</rating>
<showing>16:15:00</showing>
<showing>19:05:00</showing>
<showing>21:40:00</showing>
</movie>
<movie minutes="100">
<title>shrek</title>
<rating>pg-13</rating>
<showing>16:00:00</showing>
<showing>19:00:00</showing>
<showing>21:40:00</showing>
</movie>
</theater>
表b中定义了一个theater(电影院)类, 它包含了xmlserializer使用的属性映射.
表b
using system;
using system.xml.serialization;
namespace articles.techrepublic.xmlserialization
{
 ...
下一页 摘要:
upgrade your ini files to xml with .net (cont.)
......