📄 sample22.cs
字号:
namespace apiBook
{
using System;
using System.Xml;
using System.IO;
using System.Data;
public class TestClass
{
public static void Main()
{
try
{
XmlDocument testXD = new XmlDocument();
testXD.LoadXml("<student Id='1'>" +
" <name>Rose</name>" +
" <dept>Computer</dept>" +
" <school>SCUT</school>" +
"</student>");
XmlComment testXC;
testXC = testXD.CreateComment("test XmlComment");
XmlDeclaration testXDn;
testXDn = testXD.CreateXmlDeclaration ("1.0",null,null);
//创建XmlDeclaration对象
testXDn.Encoding="UTF-8";
testXDn.Standalone="no";
XmlElement testXE = testXD.DocumentElement;
testXD.InsertBefore(testXDn, testXE);
testXD.InsertBefore(testXC, testXE);
XmlTextWriter writer = new XmlTextWriter (Console.Out);
writer.Formatting = Formatting.Indented;
testXD.Save(writer);
Console.WriteLine();
Console.WriteLine("克隆的XmlDeclaration对象的内容:");
XmlDeclaration cloneXDn= (XmlDeclaration) testXDn.CloneNode(true);
//使用CloneNode方法创建当前对象的拷贝
Console.WriteLine(cloneXDn.OuterXml);
}
catch (Exception e)
{
Console.WriteLine (e.ToString());
}
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -