1. /*
  2. * Copyright (c) 2000 World Wide Web Consortium,
  3. * (Massachusetts Institute of Technology, Institut National de
  4. * Recherche en Informatique et en Automatique, Keio University). All
  5. * Rights Reserved. This program is distributed under the W3C's Software
  6. * Intellectual Property License. This program is distributed in the
  7. * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  8. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  9. * PURPOSE.
  10. * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  11. */
  12. package org.w3c.dom;
  13. /**
  14. * The <code>Element</code> interface represents an element in an HTML or XML
  15. * document. Elements may have attributes associated with them; since the
  16. * <code>Element</code> interface inherits from <code>Node</code>, the
  17. * generic <code>Node</code> interface attribute <code>attributes</code> may
  18. * be used to retrieve the set of all attributes for an element. There are
  19. * methods on the <code>Element</code> interface to retrieve either an
  20. * <code>Attr</code> object by name or an attribute value by name. In XML,
  21. * where an attribute value may contain entity references, an
  22. * <code>Attr</code> object should be retrieved to examine the possibly
  23. * fairly complex sub-tree representing the attribute value. On the other
  24. * hand, in HTML, where all attributes have simple string values, methods to
  25. * directly access an attribute value can safely be used as a convenience.In
  26. * DOM Level 2, the method <code>normalize</code> is inherited from the
  27. * <code>Node</code> interface where it was moved.
  28. * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113'>Document Object Model (DOM) Level 2 Core Specification</a>.
  29. */
  30. public interface Element extends Node {
  31. /**
  32. * The name of the element. For example, in:
  33. * <pre> <elementExample
  34. * id="demo"> ... </elementExample> , </pre>
  35. * <code>tagName</code> has
  36. * the value <code>"elementExample"</code>. Note that this is
  37. * case-preserving in XML, as are all of the operations of the DOM. The
  38. * HTML DOM returns the <code>tagName</code> of an HTML element in the
  39. * canonical uppercase form, regardless of the case in the source HTML
  40. * document.
  41. */
  42. public String getTagName();
  43. /**
  44. * Retrieves an attribute value by name.
  45. * @param name The name of the attribute to retrieve.
  46. * @return The <code>Attr</code> value as a string, or the empty string
  47. * if that attribute does not have a specified or default value.
  48. */
  49. public String getAttribute(String name);
  50. /**
  51. * Adds a new attribute. If an attribute with that name is already present
  52. * in the element, its value is changed to be that of the value
  53. * parameter. This value is a simple string; it is not parsed as it is
  54. * being set. So any markup (such as syntax to be recognized as an
  55. * entity reference) is treated as literal text, and needs to be
  56. * appropriately escaped by the implementation when it is written out.
  57. * In order to assign an attribute value that contains entity
  58. * references, the user must create an <code>Attr</code> node plus any
  59. * <code>Text</code> and <code>EntityReference</code> nodes, build the
  60. * appropriate subtree, and use <code>setAttributeNode</code> to assign
  61. * it as the value of an attribute.
  62. * <br>To set an attribute with a qualified name and namespace URI, use
  63. * the <code>setAttributeNS</code> method.
  64. * @param name The name of the attribute to create or alter.
  65. * @param value Value to set in string form.
  66. * @exception DOMException
  67. * INVALID_CHARACTER_ERR: Raised if the specified name contains an
  68. * illegal character.
  69. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  70. */
  71. public void setAttribute(String name,
  72. String value)
  73. throws DOMException;
  74. /**
  75. * Removes an attribute by name. If the removed attribute is known to have
  76. * a default value, an attribute immediately appears containing the
  77. * default value as well as the corresponding namespace URI, local name,
  78. * and prefix when applicable.
  79. * <br>To remove an attribute by local name and namespace URI, use the
  80. * <code>removeAttributeNS</code> method.
  81. * @param name The name of the attribute to remove.
  82. * @exception DOMException
  83. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  84. */
  85. public void removeAttribute(String name)
  86. throws DOMException;
  87. /**
  88. * Retrieves an attribute node by name.
  89. * <br>To retrieve an attribute node by qualified name and namespace URI,
  90. * use the <code>getAttributeNodeNS</code> method.
  91. * @param name The name (<code>nodeName</code>) of the attribute to
  92. * retrieve.
  93. * @return The <code>Attr</code> node with the specified name (
  94. * <code>nodeName</code>) or <code>null</code> if there is no such
  95. * attribute.
  96. */
  97. public Attr getAttributeNode(String name);
  98. /**
  99. * Adds a new attribute node. If an attribute with that name (
  100. * <code>nodeName</code>) is already present in the element, it is
  101. * replaced by the new one.
  102. * <br>To add a new attribute node with a qualified name and namespace
  103. * URI, use the <code>setAttributeNodeNS</code> method.
  104. * @param newAttr The <code>Attr</code> node to add to the attribute list.
  105. * @return If the <code>newAttr</code> attribute replaces an existing
  106. * attribute, the replaced <code>Attr</code> node is returned,
  107. * otherwise <code>null</code> is returned.
  108. * @exception DOMException
  109. * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
  110. * different document than the one that created the element.
  111. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  112. * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
  113. * attribute of another <code>Element</code> object. The DOM user must
  114. * explicitly clone <code>Attr</code> nodes to re-use them in other
  115. * elements.
  116. */
  117. public Attr setAttributeNode(Attr newAttr)
  118. throws DOMException;
  119. /**
  120. * Removes the specified attribute node. If the removed <code>Attr</code>
  121. * has a default value it is immediately replaced. The replacing
  122. * attribute has the same namespace URI and local name, as well as the
  123. * original prefix, when applicable.
  124. * @param oldAttr The <code>Attr</code> node to remove from the attribute
  125. * list.
  126. * @return The <code>Attr</code> node that was removed.
  127. * @exception DOMException
  128. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  129. * <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
  130. * of the element.
  131. */
  132. public Attr removeAttributeNode(Attr oldAttr)
  133. throws DOMException;
  134. /**
  135. * Returns a <code>NodeList</code> of all descendant <code>Elements</code>
  136. * with a given tag name, in the order in which they are encountered in
  137. * a preorder traversal of this <code>Element</code> tree.
  138. * @param name The name of the tag to match on. The special value "*"
  139. * matches all tags.
  140. * @return A list of matching <code>Element</code> nodes.
  141. */
  142. public NodeList getElementsByTagName(String name);
  143. /**
  144. * Retrieves an attribute value by local name and namespace URI.
  145. * <br>Documents which do not support the "XML" feature will permit only
  146. * the DOM Level 1 calls for creating/setting elements and attributes.
  147. * Hence, if you specify a non-null namespace URI, these DOMs will never
  148. * find a matching node.
  149. * @param namespaceURI The namespace URI of the attribute to retrieve.
  150. * @param localName The local name of the attribute to retrieve.
  151. * @return The <code>Attr</code> value as a string, or the empty string
  152. * if that attribute does not have a specified or default value.
  153. * @since DOM Level 2
  154. */
  155. public String getAttributeNS(String namespaceURI,
  156. String localName);
  157. /**
  158. * Adds a new attribute. If an attribute with the same local name and
  159. * namespace URI is already present on the element, its prefix is
  160. * changed to be the prefix part of the <code>qualifiedName</code>, and
  161. * its value is changed to be the <code>value</code> parameter. This
  162. * value is a simple string; it is not parsed as it is being set. So any
  163. * markup (such as syntax to be recognized as an entity reference) is
  164. * treated as literal text, and needs to be appropriately escaped by the
  165. * implementation when it is written out. In order to assign an
  166. * attribute value that contains entity references, the user must create
  167. * an <code>Attr</code> node plus any <code>Text</code> and
  168. * <code>EntityReference</code> nodes, build the appropriate subtree,
  169. * and use <code>setAttributeNodeNS</code> or
  170. * <code>setAttributeNode</code> to assign it as the value of an
  171. * attribute.
  172. * @param namespaceURI The namespace URI of the attribute to create or
  173. * alter.
  174. * @param qualifiedName The qualified name of the attribute to create or
  175. * alter.
  176. * @param value The value to set in string form.
  177. * @exception DOMException
  178. * INVALID_CHARACTER_ERR: Raised if the specified qualified name
  179. * contains an illegal character, per the XML 1.0 specification .
  180. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  181. * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
  182. * malformed per the Namespaces in XML specification, if the
  183. * <code>qualifiedName</code> has a prefix and the
  184. * <code>namespaceURI</code> is <code>null</code>, if the
  185. * <code>qualifiedName</code> has a prefix that is "xml" and the
  186. * <code>namespaceURI</code> is different from "
  187. * http://www.w3.org/XML/1998/namespace", or if the
  188. * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
  189. * <code>namespaceURI</code> is different from "
  190. * http://www.w3.org/2000/xmlns/".
  191. * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
  192. * support the <code>"XML"</code> feature, since namespaces were
  193. * defined by XML.
  194. * @since DOM Level 2
  195. */
  196. public void setAttributeNS(String namespaceURI,
  197. String qualifiedName,
  198. String value)
  199. throws DOMException;
  200. /**
  201. * Removes an attribute by local name and namespace URI. If the removed
  202. * attribute has a default value it is immediately replaced. The
  203. * replacing attribute has the same namespace URI and local name, as
  204. * well as the original prefix.
  205. * <br>Documents which do not support the "XML" feature will permit only
  206. * the DOM Level 1 calls for creating/setting elements and attributes.
  207. * Hence, if you specify a non-null namespace URI, these DOMs will never
  208. * find a matching node.
  209. * @param namespaceURI The namespace URI of the attribute to remove.
  210. * @param localName The local name of the attribute to remove.
  211. * @exception DOMException
  212. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  213. * @since DOM Level 2
  214. */
  215. public void removeAttributeNS(String namespaceURI,
  216. String localName)
  217. throws DOMException;
  218. /**
  219. * Retrieves an <code>Attr</code> node by local name and namespace URI.
  220. * <br>Documents which do not support the "XML" feature will permit only
  221. * the DOM Level 1 calls for creating/setting elements and attributes.
  222. * Hence, if you specify a non-null namespace URI, these DOMs will never
  223. * find a matching node.
  224. * @param namespaceURI The namespace URI of the attribute to retrieve.
  225. * @param localName The local name of the attribute to retrieve.
  226. * @return The <code>Attr</code> node with the specified attribute local
  227. * name and namespace URI or <code>null</code> if there is no such
  228. * attribute.
  229. * @since DOM Level 2
  230. */
  231. public Attr getAttributeNodeNS(String namespaceURI,
  232. String localName);
  233. /**
  234. * Adds a new attribute. If an attribute with that local name and that
  235. * namespace URI is already present in the element, it is replaced by
  236. * the new one.
  237. * @param newAttr The <code>Attr</code> node to add to the attribute list.
  238. * @return If the <code>newAttr</code> attribute replaces an existing
  239. * attribute with the same local name and namespace URI, the replaced
  240. * <code>Attr</code> node is returned, otherwise <code>null</code> is
  241. * returned.
  242. * @exception DOMException
  243. * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
  244. * different document than the one that created the element.
  245. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  246. * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
  247. * attribute of another <code>Element</code> object. The DOM user must
  248. * explicitly clone <code>Attr</code> nodes to re-use them in other
  249. * elements.
  250. * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
  251. * support the <code>"XML"</code> feature, since namespaces were
  252. * defined by XML.
  253. * @since DOM Level 2
  254. */
  255. public Attr setAttributeNodeNS(Attr newAttr)
  256. throws DOMException;
  257. /**
  258. * Returns a <code>NodeList</code> of all the descendant
  259. * <code>Elements</code> with a given local name and namespace URI in
  260. * the order in which they are encountered in a preorder traversal of
  261. * this <code>Element</code> tree.
  262. * <br>Documents which do not support the "XML" feature will permit only
  263. * the DOM Level 1 calls for creating/setting elements and attributes.
  264. * Hence, if you specify a non-null namespace URI, these DOMs will never
  265. * find a matching node.
  266. * @param namespaceURI The namespace URI of the elements to match on. The
  267. * special value "*" matches all namespaces.
  268. * @param localName The local name of the elements to match on. The
  269. * special value "*" matches all local names.
  270. * @return A new <code>NodeList</code> object containing all the matched
  271. * <code>Elements</code>.
  272. * @since DOM Level 2
  273. */
  274. public NodeList getElementsByTagNameNS(String namespaceURI,
  275. String localName);
  276. /**
  277. * Returns <code>true</code> when an attribute with a given name is
  278. * specified on this element or has a default value, <code>false</code>
  279. * otherwise.
  280. * @param name The name of the attribute to look for.
  281. * @return <code>true</code> if an attribute with the given name is
  282. * specified on this element or has a default value, <code>false</code>
  283. * otherwise.
  284. * @since DOM Level 2
  285. */
  286. public boolean hasAttribute(String name);
  287. /**
  288. * Returns <code>true</code> when an attribute with a given local name and
  289. * namespace URI is specified on this element or has a default value,
  290. * <code>false</code> otherwise.
  291. * <br>Documents which do not support the "XML" feature will permit only
  292. * the DOM Level 1 calls for creating/setting elements and attributes.
  293. * Hence, if you specify a non-null namespace URI, these DOMs will never
  294. * find a matching node.
  295. * @param namespaceURI The namespace URI of the attribute to look for.
  296. * @param localName The local name of the attribute to look for.
  297. * @return <code>true</code> if an attribute with the given local name
  298. * and namespace URI is specified or has a default value on this
  299. * element, <code>false</code> otherwise.
  300. * @since DOM Level 2
  301. */
  302. public boolean hasAttributeNS(String namespaceURI,
  303. String localName);
  304. }