5.6.7.8.在主程序中,需要读取App.config文件中配置的变量,采用NameValueCollectionappSettings=System.Configuration.ConfigurationManager.AppSettings;来获取各个变量名和变量值。如NameV" />
搜档网
当前位置:搜档网 › C#的App.config文件的配置与读取

C#的App.config文件的配置与读取

C#的App.config文件的配置与读取

对于需要配置的常量,在App.config中进行配置,格式为:

如:

[html]view plaincopyprint?

1.

2.

3.

4.

5.

6.

7.

8.

在主程序中,需要读取App.config文件中配置的变量,采用NameValueCollection appSettings =

System.Configuration.ConfigurationManager.AppSettings;

来获取各个变量名和变量值。如

NameValueCollection appSettings =

System.Configuration.ConfigurationManager.AppSettings;

string path = appSettings["SourceFolder"];在主程序中,需要读取

App.config文件中配置的变量,采用

NameValueCollection appSettings =

System.Configuration.ConfigurationManager.AppSettings;

来获取各个变量名和变量值。如

[csharp]view plaincopyprint?

https://www.sodocs.net/doc/3d7279766.html,ValueCollection appSettings = System.Configuration.Configur

ationManager.AppSettings;

2.string path = appSettings["SourceFolder"];

INI文件读写

INI文件读写.txt男人的话就像老太太的牙齿,有多少是真的?!问:你喜欢我哪一点?答:我喜欢你离我远一点!执子之手,方知子丑,泪流满面,子不走我走。诸葛亮出山前,也没带过兵!凭啥我就要工作经验?INI文件读写文章指数:0 CSDN Blog推出文章指数概念,文章指数是对Blog文章综合评分后推算出的,综合评分项分别是该文章的点击量,回复次数,被网摘收录数量,文章长度和文章类型;满分100,每月更新一次。 ini文件(即Initialization file),这种类型的文件中通常存放的是一个程序的初始化信息。ini文件由若干个节(Section)组成,每个Section由若干键(Key)组成,每个Key可以赋相应的值。读写ini文件实际上就是读写某个的Section中相应的Key的值,而这只要借助几个函数即可完成。 一、向ini文件中写入信息的函数 1. 把信息写入系统的win.ini文件 BOOL WriteProfileString( LPCTSTR lpAppName, // 节的名字,是一个以0结束的字符串 LPCTSTR lpKeyName, // 键的名字,是一个以0结束的字符串。若为NULL,则删除整个节 LPCTSTR lpString // 键的值,是一个以0结束的字符串。若为NULL,则删除对应的键 ) 2. 把信息写入自己定义的.ini文件 BOOL WritePrivateProfileString( LPCTSTR lpAppName, // 同上 LPCTSTR lpKeyName, // 同上 LPCTSTR lpString, // 同上 LPCTSTR lpFileName // 要写入的文件的文件名。若该ini文件与程序在同一个目录下,也可使用相对 //路径,否则需要给出绝度路径。 ) 如: ::WriteProfileString("Test","id","xym"); //在win.ini中创建一个Test节,并在该节中创建一个键id,其值为xym ::WritePrivateProfileString("Test","id","xym","d:\\vc\\Ex1\\ex1.ini"); //在Ex1目录下的ex1.ini中创建一个Test节,并在该节中创建一个键id,其值为xym //若Ex1.ini文件与读写该文件的程序在同一个目录下,则上面语句也可写为: ::WritePrivateProfileString("Test","id","xym",".\\ex1.ini"); 需要注意的是,C系列的语言中,转义字符'\\'表示反斜线'\'。另外,当使用相对路径时,\\前的.号不能丢掉了。 二、从ini文件中读取数据的函数

调用jar包外配置文件

项目中,经常把一部分功能独立出来,做一个java project,然后打成jar包供其他项目引用。这时候,如果jar包中需要读取配置文件信息,则很少把该配置打进jar包,因为它不方便修改,更多都是采用jar包读取外部配置文件。案例: 项目工程名:auth -- 很明显,做鉴权使用的 项目配置文件:init.properties log4j.properties 项目引用jar包: lib/servlet-api.jar lib/log4j-1.2.15.jar lib/commons-collections-3.1.jar lib/commons-logging-1.0.4.jar lib/commons-pool.jar lib/ojdbc14.jar 读取配置文件示例: 目录结构如下:

解决方案I:自定义manifest.mf 文件 解释: Manifest-Version: 1.0 版本号,没啥特殊含义,但一定要有;Class-Path: 所有引用的jar包 注意: 每个“:”后面都要加空格,Class-Path中每个jar包间也加空格最后一行为空行 截图如下: b.通过Eclipse 到处jar包 右键项目工程----Export -- 选择Java下JAR File,下一步

件外部读取),选择导出jar包的位置; 注意:右侧的.classpath这些都不要选中,只把src下的java文件打包。

下一步 下一步:选中自定义的manifest.mf文件,完成 测试: 新建项目,导入刚刚生成的jar包和jar需要的所有包(把jar包所在工程lib下所有引用jar

Java读取txt文件中指定行内容

获取文本内容与读取文本指定行数内容浅析(java) 在此项目中直接套用以前工程中获取文本内容的方法发现一直提示“数组下标越界”,通过分析和查找得出以下心得: 获取文本内容: private static final String CHART_PATH ="D://data3"; public static void main(String[] args) throws RowsExceededException,WriteException, BiffException{ try { readFileByLines(CHART_PATH+".txt"); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } } public static void readFileByLines(String fileName) throws IOException,RowsExceededException,WriteException{ //打开文件 WritableWorkbook book = Workbook.createWorkbook( new File(CHART_PATH+".xls")); WritableSheet sheet = book.createSheet("看我", 0); //读取txt文件内容 File file = new File(fileName); FileInputStream fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis,"GBK"); BufferedReader reader = null; try { reader = new BufferedReader(isr); String temString = null; //一次读入一行,以null结束 int i = 0; while((temString = reader.readLine())!= null){ System.out.println("+++++++"+temString); String[] str = temString.split(","); for(int j= 0;j

C语言读写配置文件代码

MFC读写ini配置文件 1.新建头文件如:iniFunc.h,在编辑区域粘贴以下内容: ///////////////////////////////////////////////////////////////////////// // iniFunc.h: interface for the Cini class. #if !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED _) #define AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include class Cini { public: static DWORD ReadString (char *section, char * key, char stringtoread[], char * filename); static BOOL WriteString(LPCTSTR section, LPCTSTR key,char* stringtoadd, char *filename); Cini(); virtual ~Cini(); }; #endif // !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_) 2.新建资源文件如:iniFunc.cpp,在编辑区域黏贴以下内容: ///////////////////////////////////////////////////////////////////////// // ini.cpp: implementation of the Cini class. #include "stdafx.h" #include "ini.h" ///////////////////////////////////////////////////////////////////////// //Cini类的构造函数和析构函数 Cini::Cini() { } Cini::~Cini()

JAVA读取jar包内部配置文件

package com.test; import java.io.File; import java.io.IOException; import java.io.InputStream; import https://www.sodocs.net/doc/3d7279766.html,.URL; import java.util.Properties; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class Test9 { public static void main(String[] args) throws IOException { String jarName="/test_p.jar";//Jar包所在的位置 String fileName="config/application.properties";//文件在jar包里的路径 String resource = Test9.class.getResource(jarName).getFile(); File file = new File(resource); JarFile jarFile = new JarFile(file);//读入jar文件 JarEntry entry = jarFile.getJarEntry(fileName); InputStream input = jarFile.getInputStream(entry);//读入需要的文件 Properties props = new Properties(); props.load(input); System.out.println(props.getProperty("Driver")); jarFile.close(); } }

java读取上传excel文件和txt文件中的数据

Java 读取上传文件里的数据,记事本文件和excel文件 本文,文本文件里的数据,每列以 Tab 分隔。 其它分隔符情况下,只需修改对分隔符的判断即可 本文是将文本文件或excel文件里的数据读到List 里。 List , List, ........可以改为返回其它类型的数据集 UpLoadExcel 类里需要操作excel的 jar包 import org.apache.poi.* ; 网上可以搜索下载,简单快捷 ---------------------------------------------------------------------------- - - - public class upLoadAction extends DispatchAction { public ActionForward doAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TestForm myForm = (TestForm) form; FormFile f = myForm.getUpfisle(); //get上传文件 String fileName = f.getFileName(); // 截取文件名的后三位字符 String fileType = fileName.substring(fileName.length()-3,fileName.length()); System.out.println("导入的文件名:"+fileName+"\t 文件后缀名:"+fileType); List list = new ArrayList(); if("xls".equals(fileType)){ // 上传文件是excel时文件文件后缀名为xls list = new UpLoadExcel().getExcelData(f.getInputStream()); }else if("txt".equals(fileType)){ list = new UploadText().UploadText(f.getInputStream()); } // 操作读取出来的数据,例如: if (list.size() > 0) { String[] str = null; for(int i = 0; i < list.size(); i++) { str = list.get(i); st = "insert into student (sName,sAge,sAddress,sTelephone) values(" ; st = "'" + st + str[0] + "'"; st = ",'" + st + str[1] + "'"; st = ",'" + st + str[4] + "'"; st = ",'" + st + str[6] + "'"; st = st + ")"; ...... System.out.println(st);

读取配置文件和修改配置文件(ServiceIP.properties)(原创)

读取配置文件和修改配置文件(ServiceIP.properties)(原创) package espeed.util; import java.io.*; import java.util.Properties; /* * 配置短信服务器IP(配置文件建在SRC下,ServiceIP.properties) */ public class EditServiceIP { private static Properties properties=new Properties(); private static EditServiceIP esip; public EditServiceIP(){} public static EditServiceIP getInstance(){ if(esip==null) esip=new EditServiceIP(); return esip; } //取得短信服务器IP public String getSmsServiceIP(){ InputStream

is=EditServiceIP.class.getClassLoader().getResourceAsSt ream("ServiceIP.properties"); try { properties.load(is); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("------------取得短信服务器IP地址发生IO异常"); } String provalue=properties.getProperty("SMS.ServiceIP"); return provalue; } //修改短信服务器IP public String modifySmsServieIP(String smsServiceIP){ File file=new File(EditServiceIP.class.getClassLoader().getResource("S erviceIP.properties").getPath()); try{ properties.load(new FileInputStream(file));

java文件读写代码

1、按字节读取文件内容 2、按字符读取文件内容 3、按行读取文件内容 4、随机读取文件内容 public class ReadFromFile { /** * 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。 */ public static void readFileByBytes(String fileName) { File file = new File(fileName); InputStream in = null; try { System.out.println("以字节为单位读取文件内容,一次读一个字节:"); // 一次读一个字节 in = new FileInputStream(file); int tempbyte; while ((tempbyte = in.read()) != -1) { System.out.write(tempbyte); } in.close(); } catch (IOException e) { e.printStackTrace(); return; } try { System.out.println("以字节为单位读取文件内容,一次读多个字节:"); // 一次读多个字节 byte[] tempbytes = new byte[100]; int byteread = 0; in = new FileInputStream(fileName); ReadFromFile.showAvailableBytes(in); // 读入多个字节到字节数组中,byteread为一次读入的字节数 while ((byteread = in.read(tempbytes)) != -1) { System.out.write(tempbytes, 0, byteread); }

C#读写配置文件

Windows 应用程序: ///

///发布后就可以读取了 /// private readonly string strFileName = AppDomain.CurrentDomain.BaseDirectory + "Windows_RWConfig.exe.config"; //获得配置文件的全路径 /// ///修改配置文件 /// ///key ///value private void UpdateConfig(string key, string value) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(strFileName); //找出名称为“add”的所有元素 XmlNodeList nodes = xDoc.GetElementsByTagName("add"); for (int i = 0; i < nodes.Count; i++) { //获得元素的key属性 XmlAttribute att = nodes[i].Attributes["key"]; //根据元素的第一个属性来判断元素是不是目标元素 if (att.Value == key) { //对目标元素中的第二个属性赋值 att = nodes[i].Attributes["value"]; att.Value = value; break; } } //保存上面的修改 xDoc.Save(strFileName); } /// ///读取配置文件 /// ///

Spring中加载xml配置文件的几种方式

项目中一个需求就是所有的功能都是插件的形式装入系统,这就需要利用Spring去动态加载某一位置下的配置文件,就总结了下Spring中加载xml配置文件的方式, xml是最常见的spring 应用系统配置源。Spring中的几种容器都支持使用xml装配bean,包括:XmlBeanFactory, ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, XmlWebApplicationContext, ..... 一: XmlBeanFactory 引用资源 1.Resource cr = new ClassPathResource("applicationContext.xml"); BeanFactory bf=new XmlBeanFactory(cr); UserDao userDao = (UserDao)bf.getBean("userDao"); 二: ClassPathXmlApplicationContext 编译路径 使用ClassPathXmlApplicationContext对象获取,必须把applicationContext.xml放置到类的加载路径中,也就是Src下面 1.ApplicationContext factory=new ClassPathXmlApplicationContext("classpath:appcontext.xml"); // src目录下的 2.ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); UserDao userDao = (UserDao)context.getBean("userDao"); 3.ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext-oracle.xml","applicationContext.xml"}); UserDao userDao = (UserDao)context.getBean("userDao"); // src/conf 目录下的 4.ApplicationContext factory=new ClassPathXmlApplicationContext("conf/appcontext.xml"); 5.ApplicationContext factory=new ClassPathXmlApplicationContext("file:G:/Test/src/appcontext.xml"); 三: FileSystemXmlApplicationContext用文件系统

C#读写config配置文件

C#读写config配置文件 应用程序配置文件(App.config)是标准的XML 文件,XML 标记和属性是区分大小写的。它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序。 对于一个config文件: 对config配置文件的读写类: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Configuration; using System.ServiceModel; using System.ServiceModel.Configuration; namespace NetUtilityLib { public static class ConfigHelper { //依据连接串名字connectionName返回数据连接字符串 public static string GetConnectionStringsConfig(string connectionName) { //指定config文件读取 string file = System.Windows.Forms.Application.ExecutablePath; System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(file); string connectionString = config.ConnectionStrings.ConnectionStrings[connectionName].ConnectionString.ToString(); return connectionString; } ///

///更新连接字符串 /// ///连接字符串名称 ///连接字符串内容 ///数据提供程序名称 public static void UpdateConnectionStringsConfig(string newName, string newConString, string newProviderName) { //指定config文件读取 string file = System.Windows.Forms.Application.ExecutablePath; Configuration config = ConfigurationManager.OpenExeConfiguration(file); bool exist = false; //记录该连接串是否已经存在 //如果要更改的连接串已经存在 if (config.ConnectionStrings.ConnectionStrings[newName] != null) { exist = true; } // 如果连接串已存在,首先删除它 if (exist) { config.ConnectionStrings.ConnectionStrings.Remove(newName); } //新建一个连接字符串实例

Java流(文件读写操作)

Java流 一、流的分类 ?按数据流动方向 –输入流:只能从中读取字节数据,而不能向其写出数据 –输出流:只能向其写入字节数据,而不能从中读取数据?按照流所处理的数据类型 –字节流:用于处理字节数据。 –字符流:用于处理Unicode字符数据。 ?按照流所处理的源 –节点流:从/向一个特定的IO设备读/写数据的流。(低级流)–处理流:对已存在的流进行连接和封装的流。(高级流)二、缓冲流 ?缓冲流要“套接”在相应的节点流之上,对读写的数据提供了缓冲的功能,提高了读写的效率,同时增加了一些新的方法。 ?J2SDK提供了四种缓存流: –BufferedReader –BufferedWriter –BufferedInputStream s –BufferedOutputStream

?缓冲输入流支持其父类的mark()和reset()方法: –mark()用于“标记”当前位置,就像加入了一个书签,可以使用reset()方法返回这个标记重新读取数据。?BufferedReader提供了readLine()方法用于读取一行字符串(以\r 或\n分隔)。 ?BufferedWriter提供了newLine()用于写入一个行分隔符。 ?对于输出的缓冲流,写出的数据会先在内存中缓存,使用flush()方法将会使内存中的数据立刻写出。 三、类层次 3.1、InputStream类层次

3.2、OutputStream类层次 3.3、Reader类层次

3.4、Writer类层次 四、常用的字符流与字节流的转化 说明: 1.字节流用于读写诸如图像数据之类的原始字节流。 2.字符流用于读写诸如文件数据之类的字符流。 3.低级流能和外设交流。 4.高级流能提高效率。 5.InputStreamReader 是字节流通向字符流的桥梁。 6.OutputStreamWriter 是字符流通向字节流的桥梁。

VC++操作INI配置文件的实现

VC++操作INI配置文件的实现 修改浏览权限| 删除 一.将信息写入.INI文件中. 1.所用的WINAPI函数原型为: BOOL WritePrivateProfileString( LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName ); 其中各参数的意义: LPCTSTR lpAppName 是INI文件中的一个字段名. LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名. LPCTSTR lpString 是键值,也就是变量的值,不过必须为LPCTSTR型或CString型的. LPCTSTR lpFileName 是完整的INI文件名. 2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入c:\stud\student.ini 文件中. CString strName,strTemp; int nAge; strName="张三"; nAge=12; WritePrivateProfileString("StudentInfo","Name",strName,"c:\\stud\\student.ini"); 此时c:\stud\student.ini文件中的内容如下: [StudentInfo] Name=张三 3.要将学生的年龄保存下来,只需将整型的值变为字符型即可:

strTemp.Format("%d",nAge); WritePrivateProfileString("StudentInfo","Age",strTemp,"c:\\stud\\student.ini"); 二.将信息从INI文件中读入程序中的变量. 1.所用的WINAPI函数原型为: DWORD GetPrivateProfileString( LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName ); 其中各参数的意义: 前二个参数与WritePrivateProfileString中的意义一样. lpDefault : 如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量. lpReturnedString : 接收INI文件中的值的CString对象,即目的缓存器. nSize : 目的缓存器的大小. lpFileName : 是完整的INI文件名. 2.具体使用方法:现要将上一步中写入的学生的信息读入程序中. CString strStudName; int nStudAge; GetPrivateProfileString("StudentInfo","Name","默认姓名 ",strStudName.GetBuffer(MAX_PATH),MAX_PATH,"c:\\stud\\student.ini"); 执行后strStudName 的值为:"张三",若前两个参数有误,其值为:"默认姓名". 3.读入整型值要用另一个WINAPI函数:

配置文件(ini)的读写

用系统函数读写ini配置文件 一INI文件基础 文件扩展名为ini的文件常用于操作系统、软件等初始化或进行参数设置。ini是initial的缩写。这类文件可以用文本编辑器(如记事本)打开、编辑。 文件格式 节/段sections [section] 参数/键名parameters name=value 注解comments 注解使用分号表示(;)。在分号后面的文字,直到该行结尾都全部为注解。 ;comment text 示例 如QQ安装目录下有一个kernelInfo.ini文件,里面的内容。 [kernel] version=788 packetname=QQPetKernel.EXE ini用途 编写软件的时候需要将一些初始化的信息写入到一个配置文件中,软件启动的时候从这个配置文件中读取这些初始化的信息。软件中的一些过程数据也需要保存到ini文件中。 现在软件大都将这些配置信息写到XML中,因为XML的树形描述层次结构性清晰。这就涉及到XML 的解析,可以自己写解析方法,也可以用第三方库(如TinyXML、CMarkup等)来解析XML。 更多类容可以参考https://www.sodocs.net/doc/3d7279766.html,/u/5135093875 二应用程序的ini读写 系统提供给了读写ini文件的函数,都是以GetPrivateProfile开头的,常用的有下面3个。作一个简要介绍。 GetPrivateProfileString DWORD GetPrivateProfileString( LPCTSTR lpAppName,//points to section name段名 LPCTSTR lpKeyName,//points to key name键名 LPCTSTR lpDefault,//points to default string默认的键值,这个参数不能为 NULL。如果在ini文件中没有找到lpKeyName,就将赋值lpDefault,给lpReturnedString LPTSTR lpReturnedString,//points to destination buffer指向缓冲区的指针,用于保存键值 DWORD nSize,//size of destination buffer缓冲区的大小 LPCTSTR lpFileName//points to initialization filename ini文件的路径 ); 功能:读取对应段和键的值。 返回值: 返回复制到缓冲区的字符个数,并不包括字符串结尾的NULL。 如果lpAppName和lpKeyName都不为空,并且键值的长度大于了缓冲区的长度,那么就将键值切断,并在末尾添加’\0’字符,返回nSize-1。

spring读取properties

spring 框架的xml文件如何读取properties文件数据 第一步:在spring配置文件中 注意:value可以多配置几个properties文件 /db.properties 第二步: 在src目录下面建立db.properties文件 user=sa password=sa driver=com.microsoft.sqlserver.jdbc.SQLServerDriver url=jdbc:sqlserver://localhost:1433;databaseName=DB1 第三步: 在spring的配置文件中通过EL表达式的形式调用 ${user} /db.properties

java将对象保存到文件中从文件中读取对象

1.保存对象到文件中 Java语言只能将实现了Serializable接口的类的对象保存到文件中,利用如下方法即可: public static void writeObjectToFile(Object obj) { File file =new File("test.dat"); FileOutputStream out; try { out = new FileOutputStream(file); ObjectOutputStream objOut=new ObjectOutputStream(out); objOut.writeObject(obj); objOut.flush(); objOut.close(); System.out.println("write object success!"); } catch (IOException e) { System.out.println("write object failed"); e.printStackTrace(); } } 参数obj一定要实现Serializable接口,否则会抛出 java.io.NotSerializableException异常。另外,如果写入的对象是一个容器,例如List、Map,也要保证容器中的每个元素也都是实现了Serializable 接口。例如,如果按照如下方法声明一个Hashmap,并调用writeObjectToFile方法就会抛出异常。但是如果是 Hashmap就不会出问题,因为String类已经实现了Serializable接口。另外如果是自己创建的类,如果继承的基类没有实现Serializable,那么该类需要实现Serializable,否则也无法通过这种方法写入到文件中。 Object obj=new Object(); //failed,the object in map does not implement Serializable interface HashMap objMap=new HashMap(); objMap.put("test", obj); writeObjectToFile(objMap);

c读写配置文件

MSXML2::IXMLDOMDocumentPtr pDoc; MSXML2::IXMLDOMElementPtr xmlRoot ; // 创建DOMDocument对象 HRESUL T hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40)); if ( ! SUCCEEDED(hr)) { MessageBox( " 无法创建DOMDocument对象,请检查是否安装了MS XML Parser 运行库! " ); return ; } // 根节点的名称为Book // 创建元素并添加到文档中 xmlRoot = pDoc -> createElement((_bstr_t) " Book " ); // 设置属性 xmlRoot -> setA ttribute( " id " ,( const char * )m_strId); pDoc -> appendChild(xmlRoot); MSXML2::IXMLDOMElementPtr pNode; // 添加“author”元素 pNode = pDoc -> createElement((_bstr_t) " A uthor " ); pNode -> Puttext((_bstr_t)( const char * )m_strA uthor); xmlRoot -> appendChild(pNode); // 添加“Title”元素 pNode = pDoc -> createElement( " Title " ); pNode -> Puttext(( const char * )m_strTitle); xmlRoot -> appendChild(pNode); // 保存到文件 // 如果不存在就建立,存在就覆盖 pDoc -> save( " d://he.xml " ); ------------------------------------------------------------------------------------------------------------------------------------------------ MSXML2::IXMLDOMDocumentPtr pDoc; HRESUL T hr; hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40)); if (FA ILED(hr)) { MessageBox( " 无法创建DOMDocument对象,请检查是否安装了MS XML Parser 运行库! " ); return ; } // 加载文件 pDoc -> load( " d://he.xml " ); MSXML2::IXMLDOMNodePtr pNode; // 在树中查找名为Book的节点," // "表示在任意一层查找

相关主题