- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章用C#把文件转换为XML的代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
- 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
- /**//// <summary>
- /// 从这个入口启动窗体
- /// </summary>
- static void Main()
- {
- Application.Run(new Form1());
- }
- /**//// <summary>
- /// 把加载的Office文件转换为xml文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, System.EventArgs e)
- {
- saveFileDialog1.Filter = "xml 文件|*.xml";//设置打开对话框的文件过滤条件
- saveFileDialog1.Title = "保存成 xml 文件";//设置打开对话框的标题
- saveFileDialog1.FileName="";
- saveFileDialog1.ShowDialog();//打开对话框
- if(saveFileDialog1.FileName != "")//检测用户是否输入了保存文件名
- {
- mXmlDoc.Save(saveFileDialog1.FileName);//用私有对象mXmlDoc保存文件,mXmlDoc在前面声明过
- MessageBox.Show("保存成功");
- }
- }
- /**//// <summary>
- /// 把加载的xml文件转换为Office文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, System.EventArgs e)
- {
- //从私有对象dox里选取me节点,这里的一些对xml对象的操作详细说明可以参考msdn以获取更多信息
- XmlNode node=doc.DocumentElement .SelectSingleNode("me") ;
- XmlElement ele=(XmlElement)node;//获取一个xml元素
- string pic=ele.GetAttribute ("aa");//获取ele元素的aa属性并报讯在一个临时字符串变量pic
- byte[] bytes=Convert.FromBase64String (pic);//声明一个byte[]用来存放Base64解码转换过来的数据流
- //从保存对话框里获取文件保存地址
- saveFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
- saveFileDialog1.Title = "保存成 office 文件";
- saveFileDialog1.FileName="";
- saveFileDialog1.ShowDialog();
- if(saveFileDialog1.FileName != "")
- {
- //创建文件流并保存
- FileStream outfile=new System.IO .FileStream (saveFileDialog1.FileName,System.IO.FileMode.CreateNew);
- outfile.Write(bytes,0,(int)bytes.Length );
- MessageBox.Show("保存成功");
- }
- }
- /**//// <summary>
- /// 加载窗口时的一些初始化行为
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void Form1_Load(object sender, System.EventArgs e)
- {
- MessageBox.Show("欢迎使用蛙蛙牌文档转换器");
- }
- /**//// <summary>
- /// 卸载窗体时把临时变量全部释放
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void Form1_Closed(object sender, System.EventArgs e)
- {
- mXmlDoc=null;
- doc=null;
- }
- /**//// <summary>
- /// 加载office文件并编码序列花为一个XmlDocument变量
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, System.EventArgs e)
- {
- string strFileName;
- openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ;
- openFileDialog1.FilterIndex = 1;
- openFileDialog1.FileName = "";
- openFileDialog1.ShowDialog();
- strFileName = openFileDialog1.FileName;
- if(strFileName.Length != 0)
- {
- System.IO.FileStream inFile=new FileStream(strFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
- byte[] binaryData=new byte [inFile.Length];
- inFile.Read(binaryData, 0,(int)inFile.Length);
- string mStr=Convert.ToBase64String(binaryData);
- string hh=mStr;
- mXmlDoc=new System.Xml.XmlDocument();
- mStr=string.Format ("<wawa><me aa=\"{0}\"/></wawa>",mStr);
- mXmlDoc.LoadXml( mStr);
- MessageBox.Show("加载成功");
- }
- }
- /**//// <summary>
- /// 加载xml文件到私有对象dox
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, System.EventArgs e)
- {
- string strFileName;
- openFileDialog1.Filter = "xml 文件|*.xml" ;
- openFileDialog1.FilterIndex = 1;
- openFileDialog1.FileName = "";
- openFileDialog1.ShowDialog();
- strFileName = openFileDialog1.FileName;
- //If the user does not cancel, open the document.
- if(strFileName.Length != 0)
- {
- doc=new XmlDocument();
- doc.Load(strFileName);
- MessageBox.Show("加载成功");
- }
- }
- }
- }
最后此篇关于用C#把文件转换为XML的代码的文章就讲到这里了,如果你想了解更多关于用C#把文件转换为XML的代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
今天我在一个 Java 应用程序中看到了几种不同的加载文件的方法。 文件:/ 文件:// 文件:/// 这三个 URL 开头有什么区别?使用它们的首选方式是什么? 非常感谢 斯特凡 最佳答案 file
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个 javascript 文件,并且在该方法中有一个“测试”方法,我喜欢调用 C# 函数。 c# 函数与 javascript 文件不在同一文件中。 它位于 .cs 文件中。那么我该如何管理 j
需要检查我使用的文件/目录的权限 //filePath = path of file/directory access denied by user ( in windows ) File fil
我在一个目录中有很多 java 文件,我想在我的 Intellij 项目中使用它。但是我不想每次开始一个新项目时都将 java 文件复制到我的项目中。 我知道我可以在 Visual Studio 和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有 3 个组件的 Twig 文件: 文件 1: {# content-here #} 文件 2: {{ title-here }} {# content-here #}
我得到了 mod_ldap.c 和 mod_authnz_ldap.c 文件。我需要使用 Linux 命令的 mod_ldap.so 和 mod_authnz_ldap.so 文件。 最佳答案 从 c
我想使用PIE在我的项目中使用 IE7。 但是我不明白的是,我只能在网络服务器上使用 .htc 文件吗? 我可以在没有网络服务器的情况下通过浏览器加载的本地页面中使用它吗? 我在 PIE 的文档中看到
我在 CI 管道中考虑这一点,我应该首先构建和测试我的应用程序,结果应该是一个 docker 镜像。 我想知道使用构建环境在构建服务器上构建然后运行测试是否更常见。也许为此使用构建脚本。最后只需将 j
using namespace std; struct WebSites { string siteName; int rank; string getSiteName() {
我是 Linux 新手,目前正在尝试使用 ginkgo USB-CAN 接口(interface) 的 API 编程功能。为了使用 C++ 对 API 进行编程,他们提供了库文件,其中包含三个带有 .
我刚学C语言,在实现一个程序时遇到了问题将 test.txt 文件作为程序的输入。 test.txt 文件的内容是: 1 30 30 40 50 60 2 40 30 50 60 60 3 30 20
如何连接两个tcpdump文件,使一个流量在文件中出现一个接一个?具体来说,我想“乘以”一个 tcpdump 文件,这样所有的 session 将一个接一个地按顺序重复几次。 最佳答案 mergeca
我有一个名为 input.MP4 的文件,它已损坏。它来自闭路电视摄像机。我什么都试过了,ffmpeg , VLC 转换,没有运气。但是,我使用了 mediainfo和 exiftool并提取以下信息
我想做什么? 我想提取 ISO 文件并编辑其中的文件,然后将其重新打包回 ISO 文件。 (正如你已经读过的) 我为什么要这样做? 我想开始修改 PSP ISO,为此我必须使用游戏资源、 Assets
给定一个 gzip 文件 Z,如果我将其解压缩为 Z',有什么办法可以重新压缩它以恢复完全相同的 gzip 文件 Z?在粗略阅读了 DEFLATE 格式后,我猜不会,因为任何给定的文件都可能在 DEF
我必须从数据库向我的邮件 ID 发送一封带有附件的邮件。 EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Adventure Works Admin
我有一个大的 M4B 文件和一个 CUE 文件。我想将其拆分为多个 M4B 文件,或将其拆分为多个 MP3 文件(以前首选)。 我想在命令行中执行此操作(OS X,但如果需要可以使用 Linux),而
快速提问。我有一个没有实现文件的类的项目。 然后在 AppDelegate 我有: #import "AppDelegate.h" #import "SomeClass.h" @interface A
我是一名优秀的程序员,十分优秀!