1. /*
  2. * Copyright (c) 2004 World Wide Web Consortium,
  3. *
  4. * (Massachusetts Institute of Technology, European Research Consortium for
  5. * Informatics and Mathematics, Keio University). All Rights Reserved. This
  6. * work is distributed under the W3C(r) Software License [1] in the hope that
  7. * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  8. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *
  10. * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
  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.
  26. * <p ><b>Note:</b> In DOM Level 2, the method <code>normalize</code> is
  27. * inherited from the <code>Node</code> interface where it was moved.
  28. * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>Document Object Model (DOM) Level 3 Core Specification</a>.
  29. */
  30. public interface Element extends Node {
  31. /**
  32. * The name of the element. If <code>Node.localName</code> is different
  33. * from <code>null</code>, this attribute is a qualified name. For
  34. * example, in:
  35. * <pre> <elementExample id="demo"> ...
  36. * </elementExample> , </pre>
  37. * <code>tagName</code> has the value
  38. * <code>"elementExample"</code>. Note that this is case-preserving in
  39. * XML, as are all of the operations of the DOM. The HTML DOM returns
  40. * the <code>tagName</code> of an HTML element in the canonical
  41. * uppercase form, regardless of the case in the source HTML document.
  42. */
  43. public String getTagName();
  44. /**
  45. * Retrieves an attribute value by name.
  46. * @param name The name of the attribute to retrieve.
  47. * @return The <code>Attr</code> value as a string, or the empty string
  48. * if that attribute does not have a specified or default value.
  49. */
  50. public String getAttribute(String name);
  51. /**
  52. * Adds a new attribute. If an attribute with that name is already present
  53. * in the element, its value is changed to be that of the value
  54. * parameter. This value is a simple string; it is not parsed as it is
  55. * being set. So any markup (such as syntax to be recognized as an
  56. * entity reference) is treated as literal text, and needs to be
  57. * appropriately escaped by the implementation when it is written out.
  58. * In order to assign an attribute value that contains entity
  59. * references, the user must create an <code>Attr</code> node plus any
  60. * <code>Text</code> and <code>EntityReference</code> nodes, build the
  61. * appropriate subtree, and use <code>setAttributeNode</code> to assign
  62. * it as the value of an attribute.
  63. * <br>To set an attribute with a qualified name and namespace URI, use
  64. * the <code>setAttributeNS</code> method.
  65. * @param name The name of the attribute to create or alter.
  66. * @param value Value to set in string form.
  67. * @exception DOMException
  68. * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
  69. * name according to the XML version in use specified in the
  70. * <code>Document.xmlVersion</code> attribute.
  71. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  72. */
  73. public void setAttribute(String name,
  74. String value)
  75. throws DOMException;
  76. /**
  77. * Removes an attribute by name. If a default value for the removed
  78. * attribute is defined in the DTD, a new attribute immediately appears
  79. * with the default value as well as the corresponding namespace URI,
  80. * local name, and prefix when applicable. The implementation may handle
  81. * default values from other schemas similarly but applications should
  82. * use <code>Document.normalizeDocument()</code> to guarantee this
  83. * information is up-to-date.
  84. * <br>If no attribute with this name is found, this method has no effect.
  85. * <br>To remove an attribute by local name and namespace URI, use the
  86. * <code>removeAttributeNS</code> method.
  87. * @param name The name of the attribute to remove.
  88. * @exception DOMException
  89. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  90. */
  91. public void removeAttribute(String name)
  92. throws DOMException;
  93. /**
  94. * Retrieves an attribute node by name.
  95. * <br>To retrieve an attribute node by qualified name and namespace URI,
  96. * use the <code>getAttributeNodeNS</code> method.
  97. * @param name The name (<code>nodeName</code>) of the attribute to
  98. * retrieve.
  99. * @return The <code>Attr</code> node with the specified name (
  100. * <code>nodeName</code>) or <code>null</code> if there is no such
  101. * attribute.
  102. */
  103. public Attr getAttributeNode(String name);
  104. /**
  105. * Adds a new attribute node. If an attribute with that name (
  106. * <code>nodeName</code>) is already present in the element, it is
  107. * replaced by the new one. Replacing an attribute node by itself has no
  108. * effect.
  109. * <br>To add a new attribute node with a qualified name and namespace
  110. * URI, use the <code>setAttributeNodeNS</code> method.
  111. * @param newAttr The <code>Attr</code> node to add to the attribute list.
  112. * @return If the <code>newAttr</code> attribute replaces an existing
  113. * attribute, the replaced <code>Attr</code> node is returned,
  114. * otherwise <code>null</code> is returned.
  115. * @exception DOMException
  116. * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
  117. * different document than the one that created the element.
  118. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  119. * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
  120. * attribute of another <code>Element</code> object. The DOM user must
  121. * explicitly clone <code>Attr</code> nodes to re-use them in other
  122. * elements.
  123. */
  124. public Attr setAttributeNode(Attr newAttr)
  125. throws DOMException;
  126. /**
  127. * Removes the specified attribute node. If a default value for the
  128. * removed <code>Attr</code> node is defined in the DTD, a new node
  129. * immediately appears with the default value as well as the
  130. * corresponding namespace URI, local name, and prefix when applicable.
  131. * The implementation may handle default values from other schemas
  132. * similarly but applications should use
  133. * <code>Document.normalizeDocument()</code> to guarantee this
  134. * information is up-to-date.
  135. * @param oldAttr The <code>Attr</code> node to remove from the attribute
  136. * list.
  137. * @return The <code>Attr</code> node that was removed.
  138. * @exception DOMException
  139. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  140. * <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
  141. * of the element.
  142. */
  143. public Attr removeAttributeNode(Attr oldAttr)
  144. throws DOMException;
  145. /**
  146. * Returns a <code>NodeList</code> of all descendant <code>Elements</code>
  147. * with a given tag name, in document order.
  148. * @param name The name of the tag to match on. The special value "*"
  149. * matches all tags.
  150. * @return A list of matching <code>Element</code> nodes.
  151. */
  152. public NodeList getElementsByTagName(String name);
  153. /**
  154. * Retrieves an attribute value by local name and namespace URI.
  155. * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  156. * , applications must use the value <code>null</code> as the
  157. * <code>namespaceURI</code> parameter for methods if they wish to have
  158. * no namespace.
  159. * @param namespaceURI The namespace URI of the attribute to retrieve.
  160. * @param localName The local name of the attribute to retrieve.
  161. * @return The <code>Attr</code> value as a string, or the empty string
  162. * if that attribute does not have a specified or default value.
  163. * @exception DOMException
  164. * NOT_SUPPORTED_ERR: May be raised if the implementation does not
  165. * support the feature <code>"XML"</code> and the language exposed
  166. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  167. * @since DOM Level 2
  168. */
  169. public String getAttributeNS(String namespaceURI,
  170. String localName)
  171. throws DOMException;
  172. /**
  173. * Adds a new attribute. If an attribute with the same local name and
  174. * namespace URI is already present on the element, its prefix is
  175. * changed to be the prefix part of the <code>qualifiedName</code>, and
  176. * its value is changed to be the <code>value</code> parameter. This
  177. * value is a simple string; it is not parsed as it is being set. So any
  178. * markup (such as syntax to be recognized as an entity reference) is
  179. * treated as literal text, and needs to be appropriately escaped by the
  180. * implementation when it is written out. In order to assign an
  181. * attribute value that contains entity references, the user must create
  182. * an <code>Attr</code> node plus any <code>Text</code> and
  183. * <code>EntityReference</code> nodes, build the appropriate subtree,
  184. * and use <code>setAttributeNodeNS</code> or
  185. * <code>setAttributeNode</code> to assign it as the value of an
  186. * attribute.
  187. * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  188. * , applications must use the value <code>null</code> as the
  189. * <code>namespaceURI</code> parameter for methods if they wish to have
  190. * no namespace.
  191. * @param namespaceURI The namespace URI of the attribute to create or
  192. * alter.
  193. * @param qualifiedName The qualified name of the attribute to create or
  194. * alter.
  195. * @param value The value to set in string form.
  196. * @exception DOMException
  197. * INVALID_CHARACTER_ERR: Raised if the specified qualified name is not
  198. * an XML name according to the XML version in use specified in the
  199. * <code>Document.xmlVersion</code> attribute.
  200. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  201. * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
  202. * malformed per the Namespaces in XML specification, if the
  203. * <code>qualifiedName</code> has a prefix and the
  204. * <code>namespaceURI</code> is <code>null</code>, if the
  205. * <code>qualifiedName</code> has a prefix that is "xml" and the
  206. * <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
  207. * http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is "xmlns" and the
  208. * <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>", or if the <code>namespaceURI</code> is "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>" and neither the <code>qualifiedName</code> nor its prefix is "xmlns".
  209. * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
  210. * support the feature <code>"XML"</code> and the language exposed
  211. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  212. * @since DOM Level 2
  213. */
  214. public void setAttributeNS(String namespaceURI,
  215. String qualifiedName,
  216. String value)
  217. throws DOMException;
  218. /**
  219. * Removes an attribute by local name and namespace URI. If a default
  220. * value for the removed attribute is defined in the DTD, a new
  221. * attribute immediately appears with the default value as well as the
  222. * corresponding namespace URI, local name, and prefix when applicable.
  223. * The implementation may handle default values from other schemas
  224. * similarly but applications should use
  225. * <code>Document.normalizeDocument()</code> to guarantee this
  226. * information is up-to-date.
  227. * <br>If no attribute with this local name and namespace URI is found,
  228. * this method has no effect.
  229. * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  230. * , applications must use the value <code>null</code> as the
  231. * <code>namespaceURI</code> parameter for methods if they wish to have
  232. * no namespace.
  233. * @param namespaceURI The namespace URI of the attribute to remove.
  234. * @param localName The local name of the attribute to remove.
  235. * @exception DOMException
  236. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  237. * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
  238. * support the feature <code>"XML"</code> and the language exposed
  239. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  240. * @since DOM Level 2
  241. */
  242. public void removeAttributeNS(String namespaceURI,
  243. String localName)
  244. throws DOMException;
  245. /**
  246. * Retrieves an <code>Attr</code> node by local name and namespace URI.
  247. * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  248. * , applications must use the value <code>null</code> as the
  249. * <code>namespaceURI</code> parameter for methods if they wish to have
  250. * no namespace.
  251. * @param namespaceURI The namespace URI of the attribute to retrieve.
  252. * @param localName The local name of the attribute to retrieve.
  253. * @return The <code>Attr</code> node with the specified attribute local
  254. * name and namespace URI or <code>null</code> if there is no such
  255. * attribute.
  256. * @exception DOMException
  257. * NOT_SUPPORTED_ERR: May be raised if the implementation does not
  258. * support the feature <code>"XML"</code> and the language exposed
  259. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  260. * @since DOM Level 2
  261. */
  262. public Attr getAttributeNodeNS(String namespaceURI,
  263. String localName)
  264. throws DOMException;
  265. /**
  266. * Adds a new attribute. If an attribute with that local name and that
  267. * namespace URI is already present in the element, it is replaced by
  268. * the new one. Replacing an attribute node by itself has no effect.
  269. * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  270. * , applications must use the value <code>null</code> as the
  271. * <code>namespaceURI</code> parameter for methods if they wish to have
  272. * no namespace.
  273. * @param newAttr The <code>Attr</code> node to add to the attribute list.
  274. * @return If the <code>newAttr</code> attribute replaces an existing
  275. * attribute with the same local name and namespace URI, the replaced
  276. * <code>Attr</code> node is returned, otherwise <code>null</code> is
  277. * returned.
  278. * @exception DOMException
  279. * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
  280. * different document than the one that created the element.
  281. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  282. * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
  283. * attribute of another <code>Element</code> object. The DOM user must
  284. * explicitly clone <code>Attr</code> nodes to re-use them in other
  285. * elements.
  286. * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
  287. * support the feature <code>"XML"</code> and the language exposed
  288. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  289. * @since DOM Level 2
  290. */
  291. public Attr setAttributeNodeNS(Attr newAttr)
  292. throws DOMException;
  293. /**
  294. * Returns a <code>NodeList</code> of all the descendant
  295. * <code>Elements</code> with a given local name and namespace URI in
  296. * document order.
  297. * @param namespaceURI The namespace URI of the elements to match on. The
  298. * special value "*" matches all namespaces.
  299. * @param localName The local name of the elements to match on. The
  300. * special value "*" matches all local names.
  301. * @return A new <code>NodeList</code> object containing all the matched
  302. * <code>Elements</code>.
  303. * @exception DOMException
  304. * NOT_SUPPORTED_ERR: May be raised if the implementation does not
  305. * support the feature <code>"XML"</code> and the language exposed
  306. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  307. * @since DOM Level 2
  308. */
  309. public NodeList getElementsByTagNameNS(String namespaceURI,
  310. String localName)
  311. throws DOMException;
  312. /**
  313. * Returns <code>true</code> when an attribute with a given name is
  314. * specified on this element or has a default value, <code>false</code>
  315. * otherwise.
  316. * @param name The name of the attribute to look for.
  317. * @return <code>true</code> if an attribute with the given name is
  318. * specified on this element or has a default value, <code>false</code>
  319. * otherwise.
  320. * @since DOM Level 2
  321. */
  322. public boolean hasAttribute(String name);
  323. /**
  324. * Returns <code>true</code> when an attribute with a given local name and
  325. * namespace URI is specified on this element or has a default value,
  326. * <code>false</code> otherwise.
  327. * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  328. * , applications must use the value <code>null</code> as the
  329. * <code>namespaceURI</code> parameter for methods if they wish to have
  330. * no namespace.
  331. * @param namespaceURI The namespace URI of the attribute to look for.
  332. * @param localName The local name of the attribute to look for.
  333. * @return <code>true</code> if an attribute with the given local name
  334. * and namespace URI is specified or has a default value on this
  335. * element, <code>false</code> otherwise.
  336. * @exception DOMException
  337. * NOT_SUPPORTED_ERR: May be raised if the implementation does not
  338. * support the feature <code>"XML"</code> and the language exposed
  339. * through the Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
  340. * @since DOM Level 2
  341. */
  342. public boolean hasAttributeNS(String namespaceURI,
  343. String localName)
  344. throws DOMException;
  345. /**
  346. * The type information associated with this element.
  347. * @since DOM Level 3
  348. */
  349. public TypeInfo getSchemaTypeInfo();
  350. /**
  351. * If the parameter <code>isId</code> is <code>true</code>, this method
  352. * declares the specified attribute to be a user-determined ID attribute
  353. * . This affects the value of <code>Attr.isId</code> and the behavior
  354. * of <code>Document.getElementById</code>, but does not change any
  355. * schema that may be in use, in particular this does not affect the
  356. * <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
  357. * node. Use the value <code>false</code> for the parameter
  358. * <code>isId</code> to undeclare an attribute for being a
  359. * user-determined ID attribute.
  360. * <br> To specify an attribute by local name and namespace URI, use the
  361. * <code>setIdAttributeNS</code> method.
  362. * @param name The name of the attribute.
  363. * @param isId Whether the attribute is a of type ID.
  364. * @exception DOMException
  365. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  366. * <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
  367. * of this element.
  368. * @since DOM Level 3
  369. */
  370. public void setIdAttribute(String name,
  371. boolean isId)
  372. throws DOMException;
  373. /**
  374. * If the parameter <code>isId</code> is <code>true</code>, this method
  375. * declares the specified attribute to be a user-determined ID attribute
  376. * . This affects the value of <code>Attr.isId</code> and the behavior
  377. * of <code>Document.getElementById</code>, but does not change any
  378. * schema that may be in use, in particular this does not affect the
  379. * <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
  380. * node. Use the value <code>false</code> for the parameter
  381. * <code>isId</code> to undeclare an attribute for being a
  382. * user-determined ID attribute.
  383. * @param namespaceURI The namespace URI of the attribute.
  384. * @param localName The local name of the attribute.
  385. * @param isId Whether the attribute is a of type ID.
  386. * @exception DOMException
  387. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  388. * <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
  389. * of this element.
  390. * @since DOM Level 3
  391. */
  392. public void setIdAttributeNS(String namespaceURI,
  393. String localName,
  394. boolean isId)
  395. throws DOMException;
  396. /**
  397. * If the parameter <code>isId</code> is <code>true</code>, this method
  398. * declares the specified attribute to be a user-determined ID attribute
  399. * . This affects the value of <code>Attr.isId</code> and the behavior
  400. * of <code>Document.getElementById</code>, but does not change any
  401. * schema that may be in use, in particular this does not affect the
  402. * <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
  403. * node. Use the value <code>false</code> for the parameter
  404. * <code>isId</code> to undeclare an attribute for being a
  405. * user-determined ID attribute.
  406. * @param idAttr The attribute node.
  407. * @param isId Whether the attribute is a of type ID.
  408. * @exception DOMException
  409. * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  410. * <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
  411. * of this element.
  412. * @since DOM Level 3
  413. */
  414. public void setIdAttributeNode(Attr idAttr,
  415. boolean isId)
  416. throws DOMException;
  417. }