1 exemplo de modelo xml.xml
<?xml versão="1.0" codificação="utf-8" ?>
<DrRoot>
<SiteName>xml操作示例</SiteName>
<SiteUrl>www.abc.com.cn</SiteUrl>
<SiteDescript>.net开源论坛</SiteDescript>
<SiteKeyWord>xml操作示例</SiteKeyWord>
<FileType>gif|jpg|rar</FileType>
<FileSize>1024</FileSize>
<Filtros>script|iframe</Filters>
<FilterEvent>onload|onmouseover</FilterEvent>
<BadWords>admin|webmaster|drbbs</BadWords>
<DisallowIP>0.0.0.0</DisallowIP>
<IsCloseReg>Falso</IsCloseReg>
<IsCloseBBS>Falso</IsCloseBBS>
<PósPagamento>5</PósPagamento>
<ReplyPay>2</ReplyPay>
<GoodPay>10</GoodPay>
<DelPost>5</DelPost>
<DelReply>2</DelReply>
<CancleGood>10</CancleGood>
</DrRoot>
2 主要方法
public string ReadValue(string key)
{
XmlDocument xd=new XmlDocument();
xd.Load(Server.MapPath("model.xml"));
XmlNodeList xnl = xd.GetElementsByTagName(chave);
if(xnl.Contagem==0)
retornar "";
outro
{
XmlNode mNode=xnl[0];
retornar mNode.InnerText;
}
}
public void UpdateValue(string nKey,string nValue)
{
if(ReadValue(nKey)!="")
{
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(Server.MapPath("model.xml"));
XmlNodeList elemList = xmlDoc.GetElementsByTagName(nKey);
XmlNode mNode=elemList[0];
mNode.InnerText=nValor;
XmlTextWriter xw = new XmlTextWriter(new StreamWriter(Server.MapPath("model.xml")));
xw.Formatting = Formatação.Recuado;
xmlDoc.WriteTo(xw);
xw.Fechar();
}
}
http://www.cnblogs.com/aqiang/archive/2006/10/24/538750.html