在InstallShield中写Web.Config 就是和操作XML文件
需要调用系统的MSXML.DOMDocument
在开发Asp.net程序后.对WebConfig有自定义动态配置 需要动态生成Web.Config
特使用以下代码实现,有什么问题,请看客拍砖
#define ERROR_XML_FILE_CREATION " Setup could not create the setting file %s. "
#define ERROR " Error "
prototype NUMBER LoadXML( STRING );
prototype OBJECT AddSetting( OBJECT , OBJECT , STRING , STRING );
//
//
// Write setting to an XML file using the MS xml parse
//
///
function LoadXML(szFilename)
OBJECT oDoc; // XML 对象
OBJECT oNode,son_oNode,son_son_oNode; // 节点
OBJECT Parent_oNode; // 当前父节点
OBJECT pi; // 指针
OBJECT oErr ;
begin
// 创建XML对象,并且初始化部分值
set oDoc = CreateObject ( " MSXML.DOMDocument " );
if (IsObject(oDoc) = FALSE ) then
SprintfBox(SEVERE, ERROR ,ERROR_XML_FILE_CREATION,szFilename);
return - 1 ;
endif;
oDoc.Async = FALSE ;
oDoc.loadXML( " <configuration/> " );
set Parent_oNode = oDoc.documentElement;
// 添加结构体 < ?xml version = " 1.0 " > 到文件头
set pi = oDoc.createProcessingInstruction( " xml " , " version= " 1.0 " encoding= " utf - 8 "" );
oDoc.insertBefore(pi,oDoc.childNodes.item( 0 ));
// 添加某些应用程序的设置,这些设置将全部出现在当前节点的子项中。
// Ajax节点
set oNode = AddSetting(oDoc,Parent_oNode, " configSections " , "" );
set oNode = AddSetting(oDoc,oNode, " sectionGroup " , "" );
oNode.setAttribute( " name " , " ajaxNet " );
set oNode = AddSetting(oDoc,oNode, " section " , "" );
oNode.setAttribute( " name " , " ajaxSettings " );
oNode.setAttribute( " type " , " Ajax.AjaxSettingsSectionHandler, Ajax " );
// appSettings节点
set oNode = AddSetting(oDoc,Parent_oNode, " appSettings " , "" );
set son_oNode = AddSetting(oDoc,oNode, " add " , "" );
son_oNode.setAttribute( " key " , " __DBACCESS__ " );
son_oNode.setAttribute( " value " , " SQL " );
set son_oNode = AddSetting(oDoc,oNode, " add " , "" );
son_oNode.setAttribute( " key " , " __AppDataFileRootPath__ " );
son_oNode.setAttribute( " value " ,WindowsVolume + " Data " );
// system.web 节点
set oNode = AddSetting(oDoc,Parent_oNode, " system.web " , "" );
set son_oNode = AddSetting(oDoc,oNode, " httpHandlers " , "" );
set son_oNode = AddSetting(oDoc,oNode, " httpRuntime " , "" );
son_oNode.setAttribute( " maxRequestLength " , " 1048576 " );
son_oNode.setAttribute( " executionTimeout " , " 3600 " );
set son_oNode = AddSetting(oDoc,oNode, " compilation " , "" );
son_oNode.setAttribute( " debug " , " true " );
set son_oNode = AddSetting(oDoc,oNode, " authentication " , "" );
son_oNode.setAttribute( " mode " , " Windows " );
set son_oNode = AddSetting(oDoc,oNode, " httpModules " , "" );
set son_oNode = AddSetting(oDoc,oNode, " globalization " , "" );
son_oNode.setAttribute( " requestEncoding " , " gb2312 " );
son_oNode.setAttribute( " responseEncoding " , " gb2312 " );
// MessageBox(oDoc.xml,SEVERE);
oDoc.save(szFilename) ;
set son_oNode = NOTHING ;
set son_son_oNode = NOTHING ;
set pi = NOTHING ;
set Parent_oNode = NOTHING ;
set oDoc = NOTHING ;
return 0 ;
end ;
//
// 在父节点上创建一个设置。
// < parent >
// < Nodename > Vaule </ Nodename >
// </ parent >
//
function OBJECT AddSetting(oDoc,oParent,szNodeName,szValue)
OBJECT oNode;
begin
// 先加入一个空行
set oNode = oDoc.createTextNode( " " );
oParent.appendChild(oNode);
// 创建一个新的节点和值
set oNode = oDoc.createElement(szNodeName);
oNode.text = szValue;
oParent.appendChild(oNode);
return oNode;
end ;
调用代码
LoadXML(IISROOTFOLDER+"某asp.net应用程序//Web.config");