c# 读写XML文件
用c#给PDA做了一个PC端的通讯程序,需要保存两个参数。用Delphi时,是保存在ini文件中,c#读写XML比较方便,就用xml文件来保存了。
class CXmlClass
{
private string XmlFilePath;
/// <summary>
/// 下载到PDA的TXT文件路径
/// </summary>
public string strDownFile;
/// <summary>
/// PDA数据文件上传到PC端的文件路径
/// </summary>
public string strUploadFile;
public CXmlClass()
{
//指定XML文件名
XmlFilePath = "config.xml";
//检测XML配置文件是否存在
if (System.IO.File.Exists(XmlFilePath))
return;
CreateDefaultXml();
}
#region " ReadXML() 读取XML配置文件的参数设置,获取下载的TXT文件路径与上传的数据文件路径"
/// <summary>
/// 读取XML配置文件的参数设置,获取下载的TXT文件路径与上传的数据文件路径
/// </summary>
/// <returns></returns>
public bool ReadXML()
{
try
{
XmlDocument xmlDoc=new XmlDocument();
//读取XML配置文件
xmlDoc.Load(XmlFilePath);
//读取XML文件节点
XmlNode rootNode = xmlDoc.SelectSingleNode("austec奥斯泰克").SelectSingleNode("参数设置");
if ( rootNode==null )
throw( new Exception("XML配置文件信息异常"));
//获取XML文件参数设置下的节点值
XmlElement downfile = (XmlElement)(rootNode.SelectSingleNode("downTxtFilePath"));
if (downfile == null)
throw (new Exception("XML配置文件信息异常"));
strDownFile= downfile.InnerText;
XmlElement uploadfile = (XmlElement)(rootNode.SelectSingleNode("uploadfilePath"));
if (uploadfile == null)
throw (new Exception("XML配置文件信息异常"));
相关文档:
using System;
using System.Web;
using System.Data;
using System.Text;
using System.Xml;
using System.IO;
namespace Baolee.GeneralMethod
{
/// <summary>
/// WriteXml 的摘要说明。
/// </summary>
public class WriteXml
{
/// <summary>
......
xml_parse解析xml文件时候,
很有可能不仅仅调用一次character_handler。
所以在获得xml节点的文本信息的时候,要用连接运算".="。
参考 http://jp2.php.net/manual/ro/function.xml-set-character-data-handler.php
ken at positive-edge dot com
30-Jan-2002
01:20
the function handler is called ......
大部分的解释型脚本语言都提供 eval 方法来完成动态代码的解释执行, C# 却并不提供(向 Java 学习)。不过在 .NET Framework 类库里面提供的 Microsoft.JScript 命名空间倒是包含了支持使用JScript 语言编译和生成代码的类。
先上代码:
该类需要你添加对程序集 Microsoft.JScript 的引用;如果把“current v ......