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>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 document type definition.
  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>nodeValue</code> attribute
  41. * on the <code>Attr</code> instance can also be used to retrieve the string
  42. * version of the attribute's value(s).
  43. * <p>In XML, where the value of an attribute can contain entity references,
  44. * the child nodes of the <code>Attr</code> node may be either
  45. * <code>Text</code> or <code>EntityReference</code> nodes (when these are
  46. * in use; see the description of <code>EntityReference</code> for
  47. * discussion). Because the DOM Core is not aware of attribute types, it
  48. * treats all attribute values as simple strings, even if the DTD or schema
  49. * declares them as having tokenized types.
  50. * <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>.
  51. */
  52. public interface Attr extends Node {
  53. /**
  54. * Returns the name of this attribute.
  55. */
  56. public String getName();
  57. /**
  58. * If this attribute was explicitly given a value in the original
  59. * document, this is <code>true</code> otherwise, it is
  60. * <code>false</code>. Note that the implementation is in charge of this
  61. * attribute, not the user. If the user changes the value of the
  62. * attribute (even if it ends up having the same value as the default
  63. * value) then the <code>specified</code> flag is automatically flipped
  64. * to <code>true</code>. To re-specify the attribute as the default
  65. * value from the DTD, the user must delete the attribute. The
  66. * implementation will then make a new attribute available with
  67. * <code>specified</code> set to <code>false</code> and the default
  68. * value (if one exists).
  69. * <br>In summary: If the attribute has an assigned value in the document
  70. * then <code>specified</code> is <code>true</code>, and the value is
  71. * the assigned value.If the attribute has no assigned value in the
  72. * document and has a default value in the DTD, then
  73. * <code>specified</code> is <code>false</code>, and the value is the
  74. * default value in the DTD.If the attribute has no assigned value in
  75. * the document and has a value of #IMPLIED in the DTD, then the
  76. * attribute does not appear in the structure model of the document.If
  77. * the <code>ownerElement</code> attribute is <code>null</code> (i.e.
  78. * because it was just created or was set to <code>null</code> by the
  79. * various removal and cloning operations) <code>specified</code> is
  80. * <code>true</code>.
  81. */
  82. public boolean getSpecified();
  83. /**
  84. * On retrieval, the value of the attribute is returned as a string.
  85. * Character and general entity references are replaced with their
  86. * values. See also the method <code>getAttribute</code> on the
  87. * <code>Element</code> interface.
  88. * <br>On setting, this creates a <code>Text</code> node with the unparsed
  89. * contents of the string. I.e. any characters that an XML processor
  90. * would recognize as markup are instead treated as literal text. See
  91. * also the method <code>setAttribute</code> on the <code>Element</code>
  92. * interface.
  93. * @exception DOMException
  94. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  95. */
  96. public String getValue();
  97. /**
  98. * On retrieval, the value of the attribute is returned as a string.
  99. * Character and general entity references are replaced with their
  100. * values. See also the method <code>getAttribute</code> on the
  101. * <code>Element</code> interface.
  102. * <br>On setting, this creates a <code>Text</code> node with the unparsed
  103. * contents of the string. I.e. any characters that an XML processor
  104. * would recognize as markup are instead treated as literal text. See
  105. * also the method <code>setAttribute</code> on the <code>Element</code>
  106. * interface.
  107. * @exception DOMException
  108. * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
  109. */
  110. public void setValue(String value)
  111. throws DOMException;
  112. /**
  113. * The <code>Element</code> node this attribute is attached to or
  114. * <code>null</code> if this attribute is not in use.
  115. * @since DOM Level 2
  116. */
  117. public Element getOwnerElement();
  118. }