XML文件由于格式规范,读写简单,所以非常适宜保存一些程序的配置信息。
下面总结一下在C#中读写XML文件的方法,随时更新。
1、获取某个节点的值。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
XDocument xdoc = XDocument.Load(@"dataConfig.xml");
this.TB_MMZS.Text = xdoc.Element("Cost").Element("BookInfo").Element("PageWordCount").Value;
this.TB_MMZS.Text = xdoc.Element("Cost").Element("BookInfo").Element("PageWordCount").Value;
2、查询XML文档。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)