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>Attr</code> interface represents an attribute in an
  15. * <code>Element</code> object. Typically the allowable values for the
  16. * attribute are defined in a schema associated with the document.
  17. * <p><code>Attr</code> objects inherit the <code>Node</code> interface, but
  18. * since they are not actually child nodes of the element they describe, the
  19. * DOM does not consider them part of the document tree. Thus, the
  20. * <code>Node</code> attributes <code>parentNode</code>,
  21. * <code>previousSibling</code>, and <code>nextSibling</code> have a
  22. * <code>null</code> value for <code>Attr</code> objects. The DOM takes the
  23. * view that attributes are properties of elements rather than having a
  24. * separate identity from the elements they are associated with; this should
  25. * make it more efficient to implement such features as default attributes
  26. * associated with all elements of a given type. Furthermore,
  27. * <code>Attr</code> nodes may not be immediate children of a
  28. * <code>DocumentFragment</code>. However, they can be associated with
  29. * <code>Element</code> nodes contained within a
  30. * <code>DocumentFragment</code>. In short, users and implementors of the
  31. * DOM need to be aware that <code>Attr</code> nodes have some things in
  32. * common with other objects inheriting the <code>Node</code> interface, but
  33. * they also are quite distinct.
  34. * <p>The attribute's effective value is determined as follows: if this
  35. * attribute has been explicitly assigned any value, that value is the
  36. * attribute's effective value; otherwise, if there is a declaration for
  37. * this attribute, and that declaration includes a default value, then that
  38. * default value is the attribute's effective value; otherwise, the
  39. * attribute does not exist on this element in the structure model until it
  40. * has been explicitly added. Note that the <code>Node.nodeValue</code>
  41. * attribute on the <code>Attr</code> instance can also be used to retrieve
  42. * the string version of the attribute's value(s).
  43. * <p> If the attribute was not explicitly given a value in the instance
  44. * document but has a default value provided by the schema associated with
  45. * the document, an attribute node will be created with
  46. * <code>specified</code> set to <code>false</code>. Removing attribute
  47. * nodes for which a default value is defined in the schema generates a new
  48. * attribute node with the default value and <code>specified</code> set to
  49. * <code>false</code>. If validation occurred while invoking
  50. * <code>Document.normalizeDocument()</code>, attribute nodes with
  51. * <code>specified</code> equals to <code>false</code> are recomputed
  52. * according to the default attribute values provided by the schema. If no
  53. * default value is associate with this attribute in the schema, the
  54. * attribute node is discarded.
  55. * <p>In XML, where the value of an attribute can contain entity references,
  56. * the child nodes of the <code>Attr</code> node may be either
  57. * <code>Text</code> or <code>EntityReference</code> nodes (when these are
  58. * in use; see the description of <code>EntityReference</code> for
  59. * discussion).
  60. * <p>The DOM Core represents all attribute values as simple strings, even if
  61. * the DTD or schema associated with the document declares them of some
  62. * specific type such as tokenized.
  63. * <p>The way attribute value normalization is performed by the DOM
  64. * implementation depends on how much the implementation knows about the
  65. * schema in use. Typically, the <code>value</code> and
  66. * <code>nodeValue</code> attributes of an <code>Attr</code> node initially
  67. * returns the normalized value given by the parser. It is also the case
  68. * after <code>Document.normalizeDocument()</code> is called (assuming the
  69. * right options have been set). But this may not be the case after
  70. * mutation, independently of whether the mutation is performed by setting
  71. * the string value directly or by changing the <code>Attr</code> child
  72. * nodes. In particular, this is true when <a href='http://www.w3.org/TR/2004/REC-xml-20040204#dt-charref'>character
  73. * references</a> are involved, given that they are not represented in the DOM and they
  74. * impact attribute value normalization. On the other hand, if the
  75. * implementation knows about the schema in use when the attribute value is
  76. * changed, and it is of a different type than CDATA, it may normalize it
  77. * again at that time. This is especially true of specialized DOM
  78. * implementations, such as SVG DOM implementations, which store attribute
  79. * values in an internal form different from a string.
  80. * <p>The following table gives some examples of the relations between the
  81. * attribute value in the original document (parsed attribute), the value as
  82. * exposed in the DOM, and the serialization of the value:
  83. * <table border='1' cellpadding='3'>
  84. * <tr>
  85. * <th>Examples</th>
  86. * <th>Parsed
  87. * attribute value</th>
  88. * <th>Initial <code>Attr.value</code></th>
  89. * <th>Serialized attribute value</th>
  90. * </tr>
  91. * <tr>
  92. * <td valign='top' rowspan='1' colspan='1'>
  93. * Character reference</td>
  94. * <td valign='top' rowspan='1' colspan='1'>
  95. * <pre>"x&#178;=5"</pre>
  96. * </td>
  97. * <td valign='top' rowspan='1' colspan='1'>
  98. * <pre>"x\u00b2=5"</pre>
  99. * </td>
  100. * <td valign='top' rowspan='1' colspan='1'>
  101. * <pre>"x&#178;=5"</pre>
  102. * </td>
  103. * </tr>
  104. * <tr>
  105. * <td valign='top' rowspan='1' colspan='1'>Built-in
  106. * character entity</td>
  107. * <td valign='top' rowspan='1' colspan='1'>
  108. * <pre>"y&lt;6"</pre>
  109. * </td>
  110. * <td valign='top' rowspan='1' colspan='1'>
  111. * <pre>"y<6"</pre>
  112. * </td>
  113. * <td valign='top' rowspan='1' colspan='1'>
  114. * <pre>"y&lt;6"</pre>
  115. * </td>
  116. * </tr>
  117. * <tr>
  118. * <td valign='top' rowspan='1' colspan='1'>Literal newline between</td>
  119. * <td valign='top' rowspan='1' colspan='1'>
  120. * <pre>
  121. * "x=5&#10;y=6"</pre>
  122. * </td>
  123. * <td valign='top' rowspan='1' colspan='1'>
  124. * <pre>"x=5 y=6"</pre>
  125. * </td>
  126. * <td valign='top' rowspan='1' colspan='1'>
  127. * <pre>"x=5&#10;y=6"</pre>
  128. * </td>
  129. * </tr>
  130. * <tr>
  131. * <td valign='top' rowspan='1' colspan='1'>Normalized newline between</td>
  132. * <td valign='top' rowspan='1' colspan='1'>
  133. * <pre>"x=5
  134. * y=6"</pre>
  135. * </td>
  136. * <td valign='top' rowspan='1' colspan='1'>
  137. * <pre>"x=5 y=6"</pre>
  138. * </td>
  139. * <td valign='top' rowspan='1' colspan='1'>
  140. * <pre>"x=5 y=6"</pre>
  141. * </td>
  142. * </tr>
  143. * <tr>
  144. * <td valign='top' rowspan='1' colspan='1'>Entity <code>e</code> with literal newline</td>
  145. * <td valign='top' rowspan='1' colspan='1'>
  146. * <pre>
  147. * <!ENTITY e '...&#10;...'> [...]> "x=5&e;y=6"</pre>
  148. * </td>
  149. * <td valign='top' rowspan='1' colspan='1'><em>Dependent on Implementation and Load Options</em></td>
  150. * <td valign='top' rowspan='1' colspan='1'><em>Dependent on Implementation and Load/Save Options</em></td>
  151. * </tr>
  152. * </table>
  153. * <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>.
  154. */
  155. public interface Attr extends Node {
  156. /**
  157. * Returns the name of this attribute. If <code>Node.localName</code> is
  158. * different from <code>null</code>, this attribute is a qualified name.
  159. */
  160. public String getName();
  161. /**
  162. * <code>True</code> if this attribute was explicitly given a value in
  163. * the instance document, <code>false</code> otherwise. If the
  164. * application changed the value of this attribute node (even if it ends
  165. * up having the same value as the default value) then it is set to
  166. * <code>true</code>. The implementation may handle attributes with
  167. * default values from other schemas similarly but applications should
  168. * use <code>Document.normalizeDocument()</code> to guarantee this
  169. * information is up-to-date.
  170. */
  171. public boolean getSpecified();
  172. /**
  173. * On retrieval, the value of the attribute is returned as a string.
  174. * Character and general entity references are replaced with their
  175. * values. See also the method <code>getAttribute</code> on the
  176. * <code>Element</code> interface.
  177. * <br>On setting, this creates a <code>Text</code> node with the unparsed
  178. * contents of the string, i.e. any characters that an XML processor
  179. * would recognize as markup are instead treated as literal text. See
  180. * also the method <code>Element.setAttribute()</code>.
  181. * <br> Some specialized implementations, such as some [<a href='http://www.w3.org/TR/2003/REC-SVG11-20030114/'>SVG 1.1</a>]
  182. * implementations, may do normalization automatically, even after
  183. * mutation; in such case, the value on retrieval may differ from the
  184. * value on setting.
  185. */
  186. public String getValue();
  187. /**
  188. * On retrieval, the value of the attribute is returned as a string.
  189. * Character and general entity references are replaced with their
  190. * values. See also the method <code>getAttribute</code> on the
  191. * <code>Element</code> interface.
  192. * <br>On setting, this creates a <code>Text</code> node with the unparsed
  193. * contents of the string, i.e. any characters that an XML processor
  194. * would recognize as markup are instead treated as literal text. See
  195. * also the method <code>Element.setAttribute()</code>.
  196. * <br> Some specialized implementations, such as some [<a href='http://www.w3.org/TR/2003/REC-SVG11-20030114/'>SVG 1.1</a>]
  197. * implementations, may do normalization automatically, even after
  198. * mutation; in such case, the value on retrieval may differ from the
  199. * value on setting.
  200. * @exception DOMException
  201. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  202. */
  203. public void setValue(String value)
  204. throws DOMException;
  205. /**
  206. * The <code>Element</code> node this attribute is attached to or
  207. * <code>null</code> if this attribute is not in use.
  208. * @since DOM Level 2
  209. */
  210. public Element getOwnerElement();
  211. /**
  212. * The type information associated with this attribute. While the type
  213. * information contained in this attribute is guarantee to be correct
  214. * after loading the document or invoking
  215. * <code>Document.normalizeDocument()</code>, <code>schemaTypeInfo</code>
  216. * may not be reliable if the node was moved.
  217. * @since DOM Level 3
  218. */
  219. public TypeInfo getSchemaTypeInfo();
  220. /**
  221. * Returns whether this attribute is known to be of type ID (i.e. to
  222. * contain an identifier for its owner element) or not. When it is and
  223. * its value is unique, the <code>ownerElement</code> of this attribute
  224. * can be retrieved using the method <code>Document.getElementById</code>
  225. * . The implementation could use several ways to determine if an
  226. * attribute node is known to contain an identifier:
  227. * <ul>
  228. * <li> If validation
  229. * occurred using an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
  230. * while loading the document or while invoking
  231. * <code>Document.normalizeDocument()</code>, the post-schema-validation
  232. * infoset contributions (PSVI contributions) values are used to
  233. * determine if this attribute is a schema-determined ID attribute using
  234. * the <a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/#term-sdi'>
  235. * schema-determined ID</a> definition in [<a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/'>XPointer</a>]
  236. * .
  237. * </li>
  238. * <li> If validation occurred using a DTD while loading the document or
  239. * while invoking <code>Document.normalizeDocument()</code>, the infoset <b>[type definition]</b> value is used to determine if this attribute is a DTD-determined ID
  240. * attribute using the <a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/#term-ddi'>
  241. * DTD-determined ID</a> definition in [<a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/'>XPointer</a>]
  242. * .
  243. * </li>
  244. * <li> from the use of the methods <code>Element.setIdAttribute()</code>,
  245. * <code>Element.setIdAttributeNS()</code>, or
  246. * <code>Element.setIdAttributeNode()</code>, i.e. it is an
  247. * user-determined ID attribute;
  248. * <p ><b>Note:</b> XPointer framework (see section 3.2 in [<a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/'>XPointer</a>]
  249. * ) consider the DOM user-determined ID attribute as being part of the
  250. * XPointer externally-determined ID definition.
  251. * </li>
  252. * <li> using mechanisms that
  253. * are outside the scope of this specification, it is then an
  254. * externally-determined ID attribute. This includes using schema
  255. * languages different from XML schema and DTD.
  256. * </li>
  257. * </ul>
  258. * <br> If validation occurred while invoking
  259. * <code>Document.normalizeDocument()</code>, all user-determined ID
  260. * attributes are reset and all attribute nodes ID information are then
  261. * reevaluated in accordance to the schema used. As a consequence, if
  262. * the <code>Attr.schemaTypeInfo</code> attribute contains an ID type,
  263. * <code>isId</code> will always return true.
  264. * @since DOM Level 3
  265. */
  266. public boolean isId();
  267. }