xml怎么写配置文件( 三 )


5.C# XMl读写配置文件<config>
<serv_ip>192.168.0.1</serv_ip>
<connect_time>30</connect_time>
<refresh_time>60</refresh_time>
<serv_port>3000</serv_port>
</config>;一般像这样就行了 很简单的
或者多个配置你可以加个item标签如:
<config>
<item>
<serv_ip>192.168.0.1</serv_ip>
【xml怎么写配置文件】<connect_time>30</connect_time>
<refresh_time>60</refresh_time>
<serv_port>3000</serv_port>
</item>
<item>
<serv_ip>192.168.0.2</serv_ip>
<connect_time>30</connect_time>
<refresh_time>60</refresh_time>
<serv_port>3000</serv_port>
</item>
</config>;假定xml文件路径为:path
读取和保存:
using system.xml;
XmlDocument xml = new XmlDocument();//声明xml
xml.Load(path);//按路径读xml文件
xmlnode root=xml.selectsinglenode("config");//指向根节点
xmlnode xn=root.selectsinglenode("serv_ip");//指向根节点下的serv_ip节点
string ip=xn.innertext;//读出里面的值 注意读取的是string 需要类型转换的话自己做
//修改:
xn.innertext="192.168.2.2";
xml.save(path);//保存更改到路径
6.如何编写或从XML配置文件中读取配置文件是XML配置文件(配置) config文件中会有像许多条目
abcd
xyz
choise1
1. NSIS共有4 XML的插件可供选择; NsisXML(由Wizou).xML插件,NsisXML(乔尔)和NSXML 使用NsisXML(由Wizou):Outfile "$%temp%\NSISTest.exe"
RequestExecutionLevel user
Installdir "$Temp"
Showinstdetails show
!include LogicLib.nsh
Page InstFiles
!define XMLFILE "$instdir\myxml.xml"
Section
StrCpy $9 "Did not exist"
nsisXML::create
nsisXML::load "${XMLFILE}"
${If} $0 = 0
;build a new basic XML file:
nsisXML::create
nsisXML::createProcessingInstruction "xml" 'version="1.0" encoding="UTF-8" standalone="yes"'
nsisXML::appendChild
nsisXML::release $2
${EndIf}
nsisXML::select '/choise'
${If} $2 = 0
StrCpy $1 $0
nsisXML::createElement "choise"
nsisXML::appendChild
${Else}
nsisXML::getText
StrCpy $9 $3
${EndIf}
DetailPrint "Old value: $9"
System::Call 'kernel32::GetTickCount()i.r5' ;Get some "random" value to save
nsisXML::setText "$5"
nsisXML::release $2
nsisXML::save "${XMLFILE}"
nsisXML::release $0
DetailPrint "Saved new value: $5"
SectionEnd
2. 在优先次运行我得到:Old value: Did not exist
Saved new value: 709289703
Completed
并在第二次运行我得到:Old value: 709289703
Saved new value: 709308687
Completed