using System;
using System.IO;
using System.Xml;class SetCFG
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("usage: {0} filename node-path:newvalue", Environment.CommandLine.Split(' ')[0]);
return;
} string sFile = args[0];
string[] nodeParam = args[1].Split(':');
if (nodeParam.Length < 2)
{
Console.WriteLine("not enough information on the nodes");
return;
} if (! File.Exists(sFile))
{
Console.WriteLine("{0} doesn't exist", sFile);
return;
} try
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(sFile);
XmlNode node = xmldoc.SelectSingleNode(nodeParam[0].Replace('|','/'));
if (node != null)
{
node.InnerText = nodeParam[1]; xmldoc.Save(sFile);
}
else
Console.WriteLine("node doesn't exist"); }
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
you need to call likeSetCFG Web.xml "/configuration|configSections:efg"since "|" has a special meaning in dos
using System.IO;
using System.Xml;class SetCFG
{
static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("usage: {0} filename node-path:newvalue", Environment.CommandLine.Split(' ')[0]);
return;
} string sFile = args[0];
string[] nodeParam = args[1].Split(':');
if (nodeParam.Length < 2)
{
Console.WriteLine("not enough information on the nodes");
return;
} if (! File.Exists(sFile))
{
Console.WriteLine("{0} doesn't exist", sFile);
return;
} try
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(sFile);
XmlNode node = xmldoc.SelectSingleNode(nodeParam[0].Replace('|','/'));
if (node != null)
{
node.InnerText = nodeParam[1]; xmldoc.Save(sFile);
}
else
Console.WriteLine("node doesn't exist"); }
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
you need to call likeSetCFG Web.xml "/configuration|configSections:efg"since "|" has a special meaning in dos
解决方案 »
- 再次提问..在XMLRPC中使用httpwebresponse类看到编码是ISO-8559-1怎么改成gb2312以便正确显示中文
- C#环境中 OWC 怎么设置字体啊,还有做好的图怎么加字!
- CurrencyManager.AddNew 的奇怪问题,帮忙!!
- 不行了,没脑子了,一个关于找树节点的递归,帮我看看吧!
- MDI编程:
- [分享]工控,自动化,C#读取OPC实例
- 为什么会更新不起?
- dataset中已经存在一个table,想要新建一个table,怎样操作
- 我在设计时对datagrid进行了数据绑定,怎么运行时数据显示不出来呀!
- 征募C#游戏爱好者,美工进行游戏项目试开发(报名帖)
- 窗口大小不能调整了
- 在Web上如何实现水晶报表的打印!!如何实现将导出文件保存到本地!!!
<configuration>efg</configuration>
现在如果xml文里有注释的话,这个程序就会出问题了。
如果去掉注释就对了,请问怎么过滤呢?
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(reader);
reader.Close();StreamWriter writer = new StreamWriter(sFile, false, System.Text.Encoding.GetEncoding("GB2312"));
xmldoc.Save(writer);
writer.Close();
注释的问题如下:
我的web.xml 文档如下:<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>abc</configSections>
<!-- ToDo: this appSettings is copied from Mars -->
<appSettings>
<rag>liyouxin</rag>
<datasource>sql.liyouxin.connect</datasource >
<others>
<name>test</name>
<pwd>abc</pwd>
</others>
</appSettings>
</configuration>
如果<!-- ToDo: this appSettings is copied from Mars -->注释存在的话
程序就在找节点的时候出错了,去掉就好了,
怎么才能过滤掉注释呢?或者让他不起作用。
我现在结帖,如果能帮这个忙,我新开30分的帖子,说话算数的。
thanks