c# 读xml文件
2014-01-12 22:50 每天努力一点点 阅读(143) 评论(0) 编辑 收藏 举报XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("cmdCfg.xml"); XmlNodeList nodeList = xmlDoc.SelectSingleNode("config").ChildNodes; if (nodeList != null) { foreach (XmlNode cmdNode in nodeList) { XmlElement cmdElement = (XmlElement)cmdNode; string id = cmdElement.GetAttribute("id"); XmlNodeList nls = cmdElement.ChildNodes; string showName = cmdNode.SelectSingleNode("show_name").InnerText; string path = cmdNode.SelectSingleNode("path").InnerText; string paramStr = cmdNode.SelectSingleNode("param_str").InnerText; XmlNode paramDetailNode = cmdNode.SelectSingleNode("param_detail[@name='param1']"); string paramDeatilShowName = paramDetailNode.SelectSingleNode("show_name").InnerText; } }
xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<config>
<cmd id="replace">
<show_name>字符串替换</show_name>
<path>sed</path>
<param_str>-i ‘s/${param1}/${param2}' ${param3}</param_str>
<param_detail name="param1">
<show_name>目标:</show_name>
<type>textbox</type>
<length>10</length>
</param_detail>
<param_detail name="param2">
<show_name>替换为:</show_name>
<type>textbox</type>
<length>10</length>
</param_detail>
<param_detail name="param3">
<show_name>文件路径:</show_name>
<type>file</type>
<length>50</length>
</param_detail>
<screen_out_redirect_to_file>false</screen_out_redirect_to_file>
</cmd>
</config>