Element


Element org.w3c.dom

Java 1.4

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 may need to use the Attr interface because the expansion of such an entity reference can result in a subtree of nodes beneath the Attr object. Whenver possible, however, it is much easier to work with the methods that treat attribute values as plain strings. Note also that in addition to the attribute methods defined by the Element interface you can also obtain a NamedNodeMap of Attr objects with the getAttributes( ) method of the Node interface.

Finally, note also that getAttribute( ) and related methods and hasAttribute( ) and related methods return the value of or test for the existance of both explicitly specified attributes, and also attributes for which a default value is specified in the document DTD. If you need to determine whether an attribute was explicitly specified in the document, obtain its Attr object, and use its getSpecified( ) method.

Figure 21-9. org.w3c.dom.Element

 public interface  Element  extends Node {  // Public Instance Methods  String  getAttribute  (String  name  );        Attr  getAttributeNode  (String  name  );        Attr  getAttributeNodeNS  (String  namespaceURI  , String  localName  )          throws DOMException;        String  getAttributeNS  (String  namespaceURI  , String  localName  )          throws DOMException;        NodeList  getElementsByTagName  (String  name  );        NodeList  getElementsByTagNameNS  (String  namespaceURI  , String  localName  )          throws DOMException;  5.0  TypeInfo  getSchemaTypeInfo  ( );        String  getTagName  ( );        boolean  hasAttribute  (String  name  );        boolean  hasAttributeNS  (String  namespaceURI  , String  localName  )          throws DOMException;        void  removeAttribute  (String  name  ) throws DOMException;        Attr  removeAttributeNode  (Attr  oldAttr  ) throws DOMException;        void  removeAttributeNS  (String  namespaceURI  , String  localName  )          throws DOMException;        void  setAttribute  (String  name  , String  value  ) throws DOMException;        Attr  setAttributeNode  (Attr  newAttr  ) throws DOMException;        Attr  setAttributeNodeNS  (Attr  newAttr  ) throws DOMException;        void  setAttributeNS  (String  namespaceURI  , String  qualifiedName  , String  value  )          throws DOMException;  5.0  void  setIdAttribute  (String  name  , boolean  isId  ) throws DOMException;  5.0  void  setIdAttributeNode  (Attr  idAttr  , boolean  isId  ) throws DOMException;  5.0  void  setIdAttributeNS  (String  namespaceURI  , String  localName  , boolean  isId  )          throws DOMException;   } 

Returned By

Attr.getOwnerElement( ) , Document.{createElement( ) , createElementNS( ) , getdocumentElement( ) , getElementById( )}



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net