XmlNode.GetPrefixOfNamespace(String) XmlNode.GetPrefixOfNamespace(String) XmlNode.GetPrefixOfNamespace(String) XmlNode.GetPrefixOfNamespace(String) Method


現在のノードのスコープ内にある指定した名前空間 URI に対する最も近い xmlns 宣言を検索し、宣言で定義されているプレフィックスを返します。Looks up the closest xmlns declaration for the given namespace URI that is in scope for the current node and returns the prefix defined in that declaration.

 virtual System::String ^ GetPrefixOfNamespace(System::String ^ namespaceURI);
public virtual string GetPrefixOfNamespace (string namespaceURI);
abstract member GetPrefixOfNamespace : string -> string
override this.GetPrefixOfNamespace : string -> string
Public Overridable Function GetPrefixOfNamespace (namespaceURI As String) As String


String String String String

検索対象のプリフィックスを持つ名前空間 URI。The namespace URI whose prefix you want to find.


指定した名前空間 URI のプリフィックス。The prefix for the specified namespace URI.

次の例では、XML ドキュメントに新しい要素を追加します。The following example adds a new element to the XML document.

#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 node.
   String^ prefix = root->GetPrefixOfNamespace( "urn:samples" );
   XmlElement^ elem = doc->CreateElement( prefix, "style", "urn:samples" );
   elem->InnerText = "hardcover";
   //Add the node to the document.
   root->AppendChild( elem );
   Console::WriteLine( "Display the modified XML..." );
   doc->Save( Console::Out );

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>" +

    XmlNode root = doc.FirstChild;

    //Create a new node.
    string prefix = root.GetPrefixOfNamespace("urn:samples");
    XmlElement elem = doc.CreateElement(prefix, "style", "urn:samples");
    elem.InnerText = "hardcover";

    //Add the node to the document.

    Console.WriteLine("Display the modified XML...");

Option Strict
Option Explicit

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>" & _
        Dim root As XmlNode = doc.FirstChild
        'Create a new node.
        Dim prefix As String = root.GetPrefixOfNamespace("urn:samples")
        Dim elem As XmlElement = doc.CreateElement(prefix, "style", "urn:samples")
        elem.InnerText = "hardcover"
        'Add the node to the document.
        Console.WriteLine("Display the modified XML...")
    End Sub 'Main 
End Class 'Sample


このメソッドは、ドキュメントオブジェクトモデル (DOM) の Microsoft 拡張機能です。This method is a Microsoft extension to the Document Object Model (DOM).