Name

Document

Synopsis

This interface represents a DOM document, and an object that implements this interface serves as the root of a DOM document tree. Most of the methods defined by the Document interface are “factory methods” that are used to create various types of nodes that can be inserted into this document. Note that there are two versions of the methods for creating attributes and elements. The methods with “NS” in their name are namespace-aware and require the attribute or element name to be specified as a combination of a namespace URI and a local name. You’ll notice that throughout the DOM API, methods with “NS” in their names are namespace-aware. Other important methods include the following:

getElementsByTagName( ) and its namespace-aware variant getElementsByTagNameNS( ) search the document tree for Element nodes that have the specified tag name and return a NodeList containing those matching nodes. The Element interface defines methods by the same names that search only within the subtree defined by an Element.

getElementById( ) is a related method that searches the document tree for a single element with the specified unique value for an ID attribute. This is useful when you use an ID attribute to uniquely identify certain tags within an XML document. Note that this method does not search for attributes that are named “id” or “ID”. It searches for attributes whose XML type (as declared in the document’s DTD) is ID. Such attributes are often named “id”, but this is ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.