如今在面向对象和XML盛行的时代,能够很好的发挥二者的特长,并协调合作,未来的网络结构和网络开发的模式将会有质的改变。网络开发将逐步的走向系统化、模块化、精尖化。所以呢,能够很好的运用好这些新的东西对于我们从事网络开发的人很重要。这是一个简单的小例子,实现了对象转化为XML。如果欠缺之处,希望大家批评指正。
前台调用:
 1将对象序列化为XML文档using System;
 2将对象序列化为XML文档using Bmc;
 3将对象序列化为XML文档
 4将对象序列化为XML文档public partial class _Default : System.Web.UI.Page 
 5
具体操作类:
 1将对象序列化为XML文档using System;
 2将对象序列化为XML文档using System.Data;
 3将对象序列化为XML文档using System.Configuration;
 4将对象序列化为XML文档using System.Web;
 5将对象序列化为XML文档using System.Web.Security;
 6将对象序列化为XML文档using System.Web.UI;
 7将对象序列化为XML文档using System.Web.UI.WebControls;
 8将对象序列化为XML文档using System.Web.UI.WebControls.WebParts;
 9将对象序列化为XML文档using System.Web.UI.HtmlControls;
10将对象序列化为XML文档using System.IO;
11将对象序列化为XML文档using System.Xml.Serialization;
12将对象序列化为XML文档
13

相关的实体类:
 1将对象序列化为XML文档using System;
 2将对象序列化为XML文档using System.Data;
 3将对象序列化为XML文档using System.Configuration;
 4将对象序列化为XML文档using System.Collections;
 5将对象序列化为XML文档using System.Collections.Generic;
 6将对象序列化为XML文档
 7将对象序列化为XML文档namespace Bmc
 8}
运行结果: 注意:最开始的XML说明缺少了encoding="utf-8"?
 1将对象序列化为XML文档<?xml version="1.0"?>
 2将对象序列化为XML文档<CommentArray xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 3将对象序列化为XML文档  <iArray>
 4将对象序列化为XML文档    <Comment>
 5将对象序列化为XML文档      <ID>1</ID>
 6将对象序列化为XML文档      <userName>first</userName>
 7将对象序列化为XML文档      <EditTime>2007-11-07T18:27:33.15625+08:00</EditTime>
 8将对象序列化为XML文档      <states>1</states>
 9将对象序列化为XML文档    </Comment>
10将对象序列化为XML文档    <Comment>
11将对象序列化为XML文档      <ID>2</ID>
12将对象序列化为XML文档      <userName>second</userName>
13将对象序列化为XML文档      <EditTime>2007-11-07T18:27:33.15625+08:00</EditTime>
14将对象序列化为XML文档      <states>1</states>
15将对象序列化为XML文档    </Comment>
16将对象序列化为XML文档  </iArray>
17将对象序列化为XML文档</CommentArray
改进办法:使用指定的 TextWriter 序列化指定的 Object 并将 XML 文档写入文件。
 1    }

改进后的结果:

 1将对象序列化为XML文档<?xml version="1.0" encoding="utf-8"?>
 2将对象序列化为XML文档<CommentArray xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 3将对象序列化为XML文档  <iArray>
 4将对象序列化为XML文档    <Comment>
 5将对象序列化为XML文档      <ID>1</ID>
 6将对象序列化为XML文档      <userName>first</userName>
 7将对象序列化为XML文档      <EditTime>2007-11-07T18:55:41.9375+08:00</EditTime>
 8将对象序列化为XML文档      <states>1</states>
 9将对象序列化为XML文档    </Comment>
10将对象序列化为XML文档    <Comment>
11将对象序列化为XML文档      <ID>2</ID>
12将对象序列化为XML文档      <userName>second</userName>
13将对象序列化为XML文档      <EditTime>2007-11-07T18:55:41.9375+08:00</EditTime>
14将对象序列化为XML文档      <states>1</states>
15将对象序列化为XML文档    </Comment>
16将对象序列化为XML文档  </iArray>
17将对象序列化为XML文档</CommentArray>

相关文章:

  • 2021-07-14
  • 2021-06-09
  • 2022-12-23
  • 2021-10-12
  • 2021-11-23
  • 2022-12-23
  • 2022-02-10
  • 2021-11-27
猜你喜欢
  • 2022-01-27
  • 2022-12-23
  • 2021-07-19
  • 2021-12-01
  • 2021-10-09
  • 2022-12-23
  • 2022-02-06
相关资源
相似解决方案