打印

[asp.net教程] 用c#把文件转换为xml 1

用c#把文件转换为xml 1

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

TOP

返回顶部
AYBlue

Processed in 0.061342 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-10 12:02 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP