指定した名前に一致するすべての子孫の要素のリストを格納している XmlNodeList を返します。
オーバーロードの一覧
指定した Name に一致するすべての子孫の要素のリストを格納している XmlNodeList を返します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function GetElementsByTagName(String) As XmlNodeList
[C#] public virtual XmlNodeList GetElementsByTagName(string);
[C++] public: virtual XmlNodeList* GetElementsByTagName(String*);
[JScript] public function GetElementsByTagName(String) : XmlNodeList;
指定した LocalName および NamespaceURI に一致するすべての子孫の要素のリストを格納している XmlNodeList を返します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function GetElementsByTagName(String, String) As XmlNodeList
[C#] public virtual XmlNodeList GetElementsByTagName(string, string);
[C++] public: virtual XmlNodeList* GetElementsByTagName(String*, String*);
[JScript] public function GetElementsByTagName(String, String) : XmlNodeList;
使用例
[Visual Basic, C#, C++] XmlDocument オブジェクトを作成し、 GetElmentsByTagName メソッドとその結果の XmlNodeList オブジェクトを使用して、すべての書籍のタイトルを表示する例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、GetElementsByTagName のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Option Explicit
Option Strict
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
'Create the XmlDocument.
Dim doc As New XmlDocument()
doc.Load("books.xml")
'Display all the book titles.
Dim elemList As XmlNodeList = doc.GetElementsByTagName("title")
Dim i As Integer
For i = 0 To elemList.Count - 1
Console.WriteLine(elemList(i).InnerXml)
Next i
End Sub 'Main
End Class 'Sample
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");
//Display all the book titles.
XmlNodeList elemList = doc.GetElementsByTagName("title");
for (int i=0; i < elemList.Count; i++)
{
Console.WriteLine(elemList[i].InnerXml);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
//Create the XmlDocument.
XmlDocument* doc = new XmlDocument();
doc->Load(S"books.xml");
//Display all the book titles.
XmlNodeList* elemList = doc->GetElementsByTagName(S"title");
for (int i=0; i < elemList->Count; i++)
{
Console::WriteLine(elemList->ItemOf[i]->InnerXml);
}
}
この例では、入力として、 books.xml というファイルを使用しています。
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。