XmlNode.GetNamespaceOfPrefix メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlNode.GetNamespaceOfPrefix メソッドの意味・解説 

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。

解説解説
使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

XmlNode.GetNamespaceOfPrefix メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlNode.GetNamespaceOfPrefix メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS