XmlNamespaceManager.LookupNamespace(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 접두사에 대한 네임스페이스 URI를 가져옵니다.
public:
virtual System::String ^ LookupNamespace(System::String ^ prefix);
public virtual string LookupNamespace(string prefix);
public virtual string? LookupNamespace(string prefix);
abstract member LookupNamespace : string -> string
override this.LookupNamespace : string -> string
Public Overridable Function LookupNamespace (prefix As String) As String
매개 변수
- prefix
- String
확인할 네임스페이스 URI의 접두사입니다. 기본 네임스페이스를 일치하려면 String.Empty를 전달합니다.
반품
매핑된 네임스페이스가 없거나 매핑된 네임스페이스가 없는 경우의 네임스페이스 URI prefixnull 입니다. 반환된 문자열은 원자화됩니다.
원자화된 문자열에 대한 자세한 내용은 클래스를 XmlNameTable 참조하세요.
구현
예제
다음 예제에서는 접두사/네임스페이스 쌍을 XmlNamespaceManager추가한 다음 컬렉션의 모든 쌍을 표시합니다.
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
Sample test = new Sample();
}
public Sample()
{
// Create the XmlNamespaceManager.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
// Add prefix/namespace pairs to the XmlNamespaceManager.
nsmgr.AddNamespace("", "www.wideworldimporters.com"); //Adds a default namespace.
nsmgr.AddNamespace("europe", "www.wideworldimporters.com/europe");
nsmgr.PushScope(); //Pushes a namespace scope on the stack.
nsmgr.AddNamespace("", "www.lucernepublishing.com"); //Adds another default namespace.
nsmgr.AddNamespace("partners", "www.lucernepublishing.com/partners");
Console.WriteLine("Show all the prefix/namespace pairs in the XmlNamespaceManager...");
ShowAllNamespaces(nsmgr);
}
private void ShowAllNamespaces(XmlNamespaceManager nsmgr)
{
do{
foreach (String prefix in nsmgr)
{
Console.WriteLine("Prefix={0}, Namespace={1}", prefix,nsmgr.LookupNamespace(prefix));
}
}
while (nsmgr.PopScope());
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim test As New Sample()
End Sub
Public Sub New()
' Create the XmlNamespaceManager.
Dim nt As New NameTable()
Dim nsmgr As New XmlNamespaceManager(nt)
' Add prefix/namespace pairs to the XmlNamespaceManager.
nsmgr.AddNamespace("", "www.wideworldimporters.com") 'Adds a default namespace.
nsmgr.AddNamespace("europe", "www.wideworldimporters.com/europe")
nsmgr.PushScope() 'Pushes a namespace scope on the stack.
nsmgr.AddNamespace("", "www.lucernepublishing.com") 'Adds another default namespace.
nsmgr.AddNamespace("partners", "www.lucernepublishing.com/partners")
Console.WriteLine("Show all the prefix/namespace pairs in the XmlNamespaceManager...")
ShowAllNamespaces(nsmgr)
End Sub
Private Sub ShowAllNamespaces(nsmgr As XmlNamespaceManager)
Do
Dim prefix As String
For Each prefix In nsmgr
Console.WriteLine("Prefix={0}, Namespace={1}", prefix, nsmgr.LookupNamespace(prefix))
Next prefix
Loop While nsmgr.PopScope()
End Sub
End Class