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

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

XmlDocument.GetElementById メソッド

指定した ID の XmlElement を取得します

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Overridable Function
 GetElementById ( _
    elementId As String _
) As XmlElement
Dim instance As XmlDocument
Dim elementId As String
Dim returnValue As XmlElement

returnValue = instance.GetElementById(elementId)
public virtual XmlElement GetElementById (
    string elementId
)
public:
virtual XmlElement^ GetElementById (
    String^ elementId
)
public XmlElement GetElementById (
    String elementId
)
public function GetElementById (
    elementId : String
) : XmlElement

パラメータ

elementId

一致する属性 ID

戻り値
一致する IDXmlElement一致する要素が見つからない場合null 参照 (Visual Basic では Nothing)。

解説解説
使用例使用例

GetElementById メソッド使用する例を次に示します

Option Explicit
Option Strict

Imports System
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim doc As New XmlDocument()
        doc.Load("ids.xml")
        
        'Get the first element with an attribute of type ID and value
 of A111.
        'This displays the node <Person SSN="A111" Name="Fred"/>.
        Dim elem As XmlElement = doc.GetElementById("A111")
        Console.WriteLine(elem.OuterXml)
        
        'Get the first element with an attribute of type ID and value
 of A222.
        'This displays the node <Person SSN="A222" Name="Tom"/>.
        elem = doc.GetElementById("A222")
        Console.WriteLine(elem.OuterXml)
    End Sub 'Main 
End Class 'Sample
using System;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlDocument doc = new XmlDocument();
    doc.Load("ids.xml");

    //Get the first element with an attribute of type ID and value of
 A111.
    //This displays the node <Person SSN="A111" Name="Fred"/>.
    XmlElement elem = doc.GetElementById("A111");
    Console.WriteLine( elem.OuterXml );

    //Get the first element with an attribute of type ID and value of
 A222.
    //This displays the node <Person SSN="A222" Name="Tom"/>.
    elem = doc.GetElementById("A222");
    Console.WriteLine( elem.OuterXml ); 

  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->Load( "ids.xml" );
   
   //Get the first element with an attribute of type ID and value of
 A111.
   //This displays the node <Person SSN="A111" Name="Fred"/>.
   XmlElement^ elem = doc->GetElementById( "A111" );
   Console::WriteLine( elem->OuterXml );
   
   //Get the first element with an attribute of type ID and value of
 A222.
   //This displays the node <Person SSN="A222" Name="Tom"/>.
   elem = doc->GetElementById( "A222" );
   Console::WriteLine( elem->OuterXml );
}

import System.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[]
 args)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("ids.xml");

        //Get the first element with an attribute of type ID and value of
 A111.
        //This displays the node <Person SSN="A111" Name="Fred"/>.
        XmlElement elem = doc.GetElementById("A111");
        Console.WriteLine(elem.get_OuterXml());

        //Get the first element with an attribute of type ID and value of
 A222.
        //This displays the node <Person SSN="A222" Name="Tom"/>.
        elem = doc.GetElementById("A222");
        Console.WriteLine(elem.get_OuterXml());
    } //main
} //Sample

この例では、入力として、ids.xml というファイル使用してます。

<!DOCTYPE root [
  <!ELEMENT root ANY>
 
  <!ELEMENT Person ANY>
 
  <!ELEMENT Customer EMPTY>
  <!ELEMENT Team EMPTY>
  <!ATTLIST Person SSN ID #REQUIRED>
  <!ATTLIST Customer id IDREF #REQUIRED
 >
  <!ATTLIST Team members IDREFS #REQUIRED>]>
<root>
  <Person SSN='A111' Name='Fred'/>
  <Person SSN='A111'/>
  <Person SSN='A222' Name='Tom'/>
  <Customer id='A111'/>
  <Customer id='A222334444'/>
  <Team members='A222334444 A333445555'/>
</root>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlDocument.GetElementById メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlDocument.GetElementById メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlDocument.GetElementById メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



XmlDocument.GetElementById メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS