设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > ASP.NET

用C#把文件转换为XML 1

作者:佚名 出处:网络转载 时间:12-20 点击:

内容载入中...
     using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.IO;
  using System.XML;
  namespace MyWindows
  {
   /**//// <summary>
   /// 这个示例演示如何把office文件编码为XML文件以及如何把生成的XML文件转换成office文件
   /// 把文件转换成XML格式,然后就可以用web服务,.NET Remoting,WinSock等传送了(其中后两者可以不转换也可以传送)
   /// XML解决了在多层架构中数据传输的问题,比如说在客户端可以用Web服务获取服务器端的office文件,修改后再回传给服务器
   /// 只要把文件转换成XML格式,便有好多方案可以使用了,而XML具有平台无关性,你可以在服务端用.net用发布web服务,然后客户端用
   /// Java写一段applit小程序来处理发送过来的文件,当然我举的例子几乎没有任何显示意义,它却给了我们不少的启示.
   /// 另外如果你的解决方案是基于多平台的,那么他们之间的交互最好不要用远程应用程序接口调用(RPC),应该尽量用基于文档的交互,
   /// 比如说.net下的MSMQ,j2ee的JMQ.
   ///
   /// 示例中设计到好多的类,我并没有在所有的地方做过多注释,有不明白的地方请参阅MSDN,这是偶第一个windows程序,有不对的地方
   /// 欢迎各位指导
   /// </summary>
   public class Form1 : System.Windows.Forms.Form
   {
  
    /**//// <summary>
    /// 声明四个Button,一个OpenFileDialog,一个SaveFileDialog,以及两个XMLDocument
    /// </summary>
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.OpenFileDialog openFileDialog1;
    private System.Windows.Forms.SaveFileDialog saveFileDialog1;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Button button4;
    private System.XML.XMLDocument mXMLDoc;
    private System.XML.XMLDocument doc;
    private System.ComponentModel.Container components = null;
  
    public Form1()
    {
     //
     // Windows 窗体设计器支持所必需的
     //
     InitializeComponent();
  
     //
     // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
     //
    }
  
    /**//// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
     if( disposing )
     {
      if(components != null)
      {
       components.Dispose();
      }
     }
     base.Dispose( disposing );
    }
  
    Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
    /**//// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
     this.button1 = new System.Windows.Forms.Button();
     this.button2 = new System.Windows.Forms.Button();
     this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
     this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
     this.button3 = new System.Windows.Forms.Button();
     this.button4 = new System.Windows.Forms.Button();
     this.SuspendLayout();
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(96, 32);
     this.button1.Name = "button1";
     this.button1.TabIndex = 0;
     this.button1.Text = "生成XML";
     this.button1.Click += new System.EventHandler(this.button1_Click);
     //
     // button2
     //
     this.button2.Location = new System.Drawing.Point(96, 80);
     this.button2.Name = "button2";
     this.button2.TabIndex = 1;
     this.button2.Text = "生成doc";
     this.button2.Click += new System.EventHandler(this.button2_Click);
     //
     // button3
     //
     this.button3.Location = new System.Drawing.Point(8, 32);
     this.button3.Name = "button3";
     this.button3.TabIndex = 2;
     this.button3.Text = "加载doc";
     this.button3.Click += new System.EventHandler(this.button3_Click);
     //
     // button4
     //
     this.button4.Location = new System.Drawing.Point(8, 80);
     this.button4.Name = "button4";
     this.button4.TabIndex = 3;
     this.button4.Text = "加载XML";
     this.button4.Click += new System.EventHandler(this.button4_Click);
     //
     // Form1
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
     this.ClientSize = new System.Drawing.Size(184, 141);
     this.Controls.Add(this.button4);
     this.Controls.Add(this.button3);
     this.Controls.Add(this.button2);
     this.Controls.Add(this.button1);
     this.Name = "Form1";
     this.Text = "Form1";
     this.ResumeLayout(false);
     //
     //手工注册一下Load和Closed事件
     //
     this.Load += new System.EventHandler(this.Form1_Load);
     this.Closed += new System.EventHandler(this.Form1_Closed);
  
    }
    #endregion
  
  
    。

收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息