📄 sample39.cs
字号:
namespace apiBook
{
using System;
using System.Xml;
using System.IO;
using System.Collections;
public class TestXmlNodeClass
{
public static void Main()
{
XmlDocument testXD = new XmlDocument(); testXD.Load("c:\\student.xml");
XmlNodeList testXNL;
XmlNode testXN = testXD.DocumentElement; Console.WriteLine("将所有Grade节点值为3的改成值为Three");
testXNL=testXN.SelectNodes("descendant::student[grade='3']");
//使用SelectNodes方法获取匹配 XPath 表达式的节点列表
foreach (XmlNode tempXN in testXNL)
{
tempXN.LastChild.InnerText="Three";
}
Console.WriteLine("修改后的XML文挡内容:");
testXD.Save(Console.Out);
Console.WriteLine();
Console.WriteLine("下面将Computer系的第一个同学名字改为Zoe");
testXN=testXD.DocumentElement;
XmlNode tempXNS=testXN.SelectSingleNode("descendant::student[dept='Computer']");
//使用SelectSingleNode方法获取匹配XPath表达式的第一个XmlNode对象
tempXNS.FirstChild.InnerText="Zoe";
Console.WriteLine("修改后XML文档内容为:");
testXD.Save(Console.Out);
Console.WriteLine();
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -