다음을 통해 공유


XmlNode.GetNamespaceOfPrefix 메서드

현재 노드의 범위에 있는 지정된 접두사에 대해 가장 가까운 xmlns 선언을 조회하여 선언의 네임스페이스 URI를 반환합니다.

네임스페이스: System.Xml
어셈블리: System.Xml(system.xml.dll)

구문

‘선언
Public Overridable Function GetNamespaceOfPrefix ( _
    prefix As String _
) As String
‘사용 방법
Dim instance As XmlNode
Dim prefix As String
Dim returnValue As String

returnValue = instance.GetNamespaceOfPrefix(prefix)
public virtual string GetNamespaceOfPrefix (
    string prefix
)
public:
virtual String^ GetNamespaceOfPrefix (
    String^ prefix
)
public String GetNamespaceOfPrefix (
    String prefix
)
public function GetNamespaceOfPrefix (
    prefix : String
) : String

매개 변수

  • prefix
    찾으려는 네임스페이스 URI의 접두사입니다.

반환 값

지정된 접두사의 네임스페이스 URI입니다.

설명

이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

예제

다음 예제에서는 새 특성을 XML 문서에 추가합니다.

Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        
        Dim doc As New XmlDocument()
        doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "</book>")
        
        Dim root As XmlNode = doc.FirstChild
        
        'Create a new attribute.
        Dim ns As String = root.GetNamespaceOfPrefix("bk")
        Dim attr As XmlNode = doc.CreateNode(XmlNodeType.Attribute, "genre", ns)
        attr.Value = "novel"
        
        'Add the attribute to the document.
        root.Attributes.SetNamedItem(attr)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub 'Main 
End Class 'Sample
using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlNode root = doc.FirstChild;

    //Create a new attribute.
    string ns = root.GetNamespaceOfPrefix("bk");
    XmlNode attr = doc.CreateNode(XmlNodeType.Attribute, "genre", ns);
    attr.Value = "novel";

    //Add the attribute to the document.
    root.Attributes.SetNamedItem(attr);

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);

  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>"
   "<title>Pride And Prejudice</title>"
   "</book>" );
   XmlNode^ root = doc->FirstChild;
   
   //Create a new attribute.
   String^ ns = root->GetNamespaceOfPrefix( "bk" );
   XmlNode^ attr = doc->CreateNode( XmlNodeType::Attribute, "genre", ns );
   attr->Value = "novel";
   
   //Add the attribute to the document.
   root->Attributes->SetNamedItem( attr );
   Console::WriteLine( "Display the modified XML..." );
   doc->Save( Console::Out );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>"
            + "<title>Pride And Prejudice</title>"
            + "</book>");

        XmlNode root = doc.get_FirstChild();
        //Create a new attribute.
        String ns = root.GetNamespaceOfPrefix("bk");
        XmlNode attr = doc.CreateNode(XmlNodeType.Attribute, "genre", ns);
        attr.set_Value("novel");

        //Add the attribute to the document.
        root.get_Attributes().SetNamedItem(attr);

        Console.WriteLine("Display the modified XML...");
        doc.Save(Console.get_Out());
    } //main 
} //Sample

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

XmlNode 클래스
XmlNode 멤버
System.Xml 네임스페이스