📄 sample33.cs
字号:
namespace apiBook
{
using System;
using System.Xml;
using System.IO;
public class TestXmlNamespaceManagerClass
{
public static void Main()
{
NameTable testXT = new NameTable();
XmlNamespaceManager testXNM =new XmlNamespaceManager(testXT);
testXNM.AddNamespace(String.Empty, "xml:samples");
//用AddNamespace方法将给定的命名空间添加到集合
testXNM.AddNamespace("Manager", "xml:samples:XMLManager");
testXNM.AddNamespace("", "www.liZe.com");
testXNM.AddNamespace("computer","www.LiZe.com/computer");
testXNM.PushScope();
//使用PushScope方法将命名空间范围推到堆栈上
testXNM.AddNamespace("","www.LiZe-En.com");
testXNM.AddNamespace ("toefl","www.LiZe-En.com/toefl");
Console.WriteLine("XmlNamespaceManager对象里所有的前缀和命名空间:");
do
{
foreach (String pfStr in testXNM)
{
Console.WriteLine("前缀:"+pfStr);
Console.WriteLine("命名空间:"+testXNM.LookupNamespace(pfStr));
//使用LookupNamespace方法获取指定前缀的命名空间 URI
}
}
while (testXNM.PopScope());
//使用PopScope方法将命名空间范围弹出堆栈
Console.WriteLine();
String pStr = testXNM.LookupPrefix ("www.LiZe.com/computer");
//使用LookupPrefix方法查找为给定的命名空间 URI 声明的前缀
Console.WriteLine("移除为前缀"+pStr+"解析的命名空间后,管理器的内容:");
testXNM.RemoveNamespace(pStr, "www.LiZe.com/computer");
//使用RemoveNamespace方法为给定的前缀移除给定的命名空间
do
{
foreach (String pfStr in testXNM)
{
Console.WriteLine("前缀:"+pfStr);
Console.WriteLine("命名空间:"+testXNM.LookupNamespace(pfStr));
}
}
while (testXNM.PopScope());
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -