GetElementsByTagName Method (String)
Collapse the table of content
Expand the table of content

XmlElement.GetElementsByTagName Method (String)


Returns an XmlNodeList containing a list of all descendant elements that match the specified Name.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public virtual XmlNodeList GetElementsByTagName(
	string name


Type: System.String

The name tag to match. This is a qualified name. It is matched against the Name property of the matching node. The asterisk (*) is a special value that matches all tags.

Return Value

Type: System.Xml.XmlNodeList

An XmlNodeList containing a list of all matching nodes. The list is empty if there are no matching nodes.

The nodes are placed in the order in which they would be encountered in a preorder traversal of the XmlElement tree.


It is recommended that you use the XmlNode.SelectNodes or XmlNode.SelectSingleNode method instead of the GetElementsByTagName method.

The following example gets and displays all the book titles.

The example uses the file, 2books.xml, as input.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft