📄 sample17.cs
字号:
namespace apiBook
{
using System;
using System.Xml;
using System.IO;
public class TestClass
{
public static void Main()
{
XmlDocument testXD = new XmlDocument();
testXD.Load("C:\\TestXmlAttribute.xml");
XmlAttribute testXA;
testXA = testXD.CreateAttribute ("dept","computer","urn:samples");
testXA.Value = "Grade one";
XmlElement testXE = (XmlElement) testXD.DocumentElement.FirstChild;
testXE.SetAttributeNode(testXA);
XmlAttribute testXA2;
testXA2 = (XmlAttribute) testXA.CloneNode(true);
//使用CloneNode方法创建当前节点的副本
testXE = (XmlElement) testXD.DocumentElement.LastChild;
testXE.SetAttributeNode(testXA2);
Console.WriteLine("显示XML文档数据:");
Console.WriteLine();
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting = Formatting.Indented;
testXD.WriteContentTo(writer);
Console.WriteLine();
Console.Write("拷贝的对象是:");
testXA2.WriteContentTo(writer);
//使用WriteContentTo方法将节点的所有子级保存到指定的XmlWriter对象中
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -