XmlDocument.GetElementsByTagName 메서드

정의

지정된 이름과 일치하는 모든 하위 요소의 목록이 포함된 XmlNodeList를 반환합니다.

오버로드

GetElementsByTagName(String)

지정된 Name과 일치하는 모든 하위 요소의 목록이 포함된 XmlNodeList를 반환합니다.

GetElementsByTagName(String, String)

지정된 LocalNameNamespaceURI와 일치하는 모든 하위 요소의 목록이 포함된 XmlNodeList를 반환합니다.

GetElementsByTagName(String)

지정된 Name과 일치하는 모든 하위 요소의 목록이 포함된 XmlNodeList를 반환합니다.

public:
 virtual System::Xml::XmlNodeList ^ GetElementsByTagName(System::String ^ name);
public virtual System.Xml.XmlNodeList GetElementsByTagName (string name);
abstract member GetElementsByTagName : string -> System.Xml.XmlNodeList
override this.GetElementsByTagName : string -> System.Xml.XmlNodeList
Public Overridable Function GetElementsByTagName (name As String) As XmlNodeList

매개 변수

name
String

일치시킬 정규화된 이름입니다. 일치하는 노드의 Name 속성과 일치합니다. 특수 값 "*"은 모든 태그와 일치합니다.

반환

XmlNodeList

일치하는 모든 노드 목록이 포함된 XmlNodeList입니다. name과 일치하는 노드가 없으면 빈 컬렉션이 반환됩니다.

예제

다음 예제에서는 개체를 XmlDocument 만들고 메서드 및 결과 개체를 XmlNodeList 사용하여 GetElementsByTagName 모든 책 제목을 표시합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew 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 );
   }
}
using System;
using System.Xml;

public class Sample1
{
    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);
        }
    }
}
Option Explicit
Option Strict

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
End Class

이 예제에서는 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>

설명

노드는 문서에서 발견되는 순서대로 배치됩니다.

참고

메서드 대신 GetElementsByTagName 또는 XmlNode.SelectSingleNode 메서드를 XmlNode.SelectNodes 사용하는 것이 좋습니다.

적용 대상

GetElementsByTagName(String, String)

지정된 LocalNameNamespaceURI와 일치하는 모든 하위 요소의 목록이 포함된 XmlNodeList를 반환합니다.

public:
 virtual System::Xml::XmlNodeList ^ GetElementsByTagName(System::String ^ localName, System::String ^ namespaceURI);
public virtual System.Xml.XmlNodeList GetElementsByTagName (string localName, string namespaceURI);
abstract member GetElementsByTagName : string * string -> System.Xml.XmlNodeList
override this.GetElementsByTagName : string * string -> System.Xml.XmlNodeList
Public Overridable Function GetElementsByTagName (localName As String, namespaceURI As String) As XmlNodeList

매개 변수

localName
String

일치시킬 LocalName입니다. 특수 값 "*"은 모든 태그와 일치합니다.

namespaceURI
String

일치시킬 NamespaceURI입니다.

반환

XmlNodeList

일치하는 모든 노드 목록이 포함된 XmlNodeList입니다. 지정된 localNamenamespaceURI와 일치하는 노드가 없으면 빈 컬렉션이 반환됩니다.

설명

노드는 문서 트리에서 발견되는 순서대로 배치됩니다.

참고

메서드 대신 GetElementsByTagName 또는 XmlNode.SelectSingleNode 메서드를 XmlNode.SelectNodes 사용하는 것이 좋습니다.

적용 대상