XmlDocument.GetElementById メソッド
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlDocument Dim elementId As String Dim returnValue As XmlElement returnValue = instance.GetElementById(elementId)
戻り値
一致する ID の XmlElement。一致する要素が見つからない場合は null 参照 (Visual Basic では Nothing)。

一致する ID の複数の要素がドキュメントにある場合、このメソッドはドキュメントで最初に見つかった一致する要素を返します。
![]() |
---|
DOM 実装は、どの属性が型 ID かを定義する情報を持っている必要があります。型 ID の属性は XSD スキーマまたは DTD で定義できますが、このバージョンの製品では DTD で定義される属性だけをサポートします。名前が "ID" の属性は、DTD で定義されていない限り、型 ID の属性ではありません。属性が型 ID の属性かどうかが不明な実装は、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>

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlDocument.GetElementById メソッドを検索する場合は、下記のリンクをクリックしてください。

- XmlDocument.GetElementById メソッドのページへのリンク