Name

Element

Synopsis

This interface represents an element (or tag) in an XML document. getTagName( ) returns the tagname of the element, including the namespace prefix if there is one. When working with namespaces, you will probably prefer to use the namespace-aware methods defined by the Node interface. Use getNamespaceURI( ) to get the namespace URI of the element, and use getLocalName( ) to the local name of the element within that namespace. You can also use getPrefix( ) to query the namespace prefix, or setPrefix( ) to change the namespace prefix (this does not change the namespace URI).

Element defines a getElementsByTagName( ) method and a corresponding namespace-aware getElementsByTagNameNS( ) method, which behave just like the methods of the same names on the Document object, except that they search for named elements only within the subtree rooted at this Element.

The remaining methods of the Element interface are for querying and setting attribute values, testing the existence of an attribute, and removing an attribute from the Element. There are a confusing number of methods to perform these four basic attribute operations. If an attribute-related method has “NS” in its name, then it is namespace-aware. If it has “Node” in its name, then it works with Attr objects rather than with the simpler string representation of the attribute value. Attributes in XML documents may contain entity references. If your document may include entity references in attribute values, then you ...

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.