001 /*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
003 *
004 * This code is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU General Public License version 2 only, as
006 * published by the Free Software Foundation. Sun designates this
007 * particular file as subject to the "Classpath" exception as provided
008 * by Sun in the LICENSE file that accompanied this code.
009 *
010 * This code is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013 * version 2 for more details (a copy is included in the LICENSE file that
014 * accompanied this code).
015 *
016 * You should have received a copy of the GNU General Public License version
017 * 2 along with this work; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
019 *
020 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
021 * CA 95054 USA or visit www.sun.com if you need additional information or
022 * have any questions.
023 */
024
025 /*
026 * This file is available under and governed by the GNU General Public
027 * License version 2 only, as published by the Free Software Foundation.
028 * However, the following notice accompanied the original version of this
029 * file and, per its terms, should not be removed:
030 *
031 * Copyright (c) 2004 World Wide Web Consortium,
032 *
033 * (Massachusetts Institute of Technology, European Research Consortium for
034 * Informatics and Mathematics, Keio University). All Rights Reserved. This
035 * work is distributed under the W3C(r) Software License [1] in the hope that
036 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
037 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
038 *
039 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
040 */
041
042 package org.w3c.dom;
043
044 /**
045 * The <code>Element</code> interface represents an element in an HTML or XML
046 * document. Elements may have attributes associated with them; since the
047 * <code>Element</code> interface inherits from <code>Node</code>, the
048 * generic <code>Node</code> interface attribute <code>attributes</code> may
049 * be used to retrieve the set of all attributes for an element. There are
050 * methods on the <code>Element</code> interface to retrieve either an
051 * <code>Attr</code> object by name or an attribute value by name. In XML,
052 * where an attribute value may contain entity references, an
053 * <code>Attr</code> object should be retrieved to examine the possibly
054 * fairly complex sub-tree representing the attribute value. On the other
055 * hand, in HTML, where all attributes have simple string values, methods to
056 * directly access an attribute value can safely be used as a convenience.
057 * <p ><b>Note:</b> In DOM Level 2, the method <code>normalize</code> is
058 * inherited from the <code>Node</code> interface where it was moved.
059 * <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>.
060 */
061 public interface Element extends Node {
062 /**
063 * The name of the element. If <code>Node.localName</code> is different
064 * from <code>null</code>, this attribute is a qualified name. For
065 * example, in:
066 * <pre> <elementExample id="demo"> ...
067 * </elementExample> , </pre>
068 * <code>tagName</code> has the value
069 * <code>"elementExample"</code>. Note that this is case-preserving in
070 * XML, as are all of the operations of the DOM. The HTML DOM returns
071 * the <code>tagName</code> of an HTML element in the canonical
072 * uppercase form, regardless of the case in the source HTML document.
073 */
074 public String getTagName();
075
076 /**
077 * Retrieves an attribute value by name.
078 * @param name The name of the attribute to retrieve.
079 * @return The <code>Attr</code> value as a string, or the empty string
080 * if that attribute does not have a specified or default value.
081 */
082 public String getAttribute(String name);
083
084 /**
085 * Adds a new attribute. If an attribute with that name is already present
086 * in the element, its value is changed to be that of the value
087 * parameter. This value is a simple string; it is not parsed as it is
088 * being set. So any markup (such as syntax to be recognized as an
089 * entity reference) is treated as literal text, and needs to be
090 * appropriately escaped by the implementation when it is written out.
091 * In order to assign an attribute value that contains entity
092 * references, the user must create an <code>Attr</code> node plus any
093 * <code>Text</code> and <code>EntityReference</code> nodes, build the
094 * appropriate subtree, and use <code>setAttributeNode</code> to assign
095 * it as the value of an attribute.
096 * <br>To set an attribute with a qualified name and namespace URI, use
097 * the <code>setAttributeNS</code> method.
098 * @param name The name of the attribute to create or alter.
099 * @param value Value to set in string form.
100 * @exception DOMException
101 * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
102 * name according to the XML version in use specified in the
103 * <code>Document.xmlVersion</code> attribute.
104 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
105 */
106 public void setAttribute(String name, String value)
107 throws DOMException;
108
109 /**
110 * Removes an attribute by name. If a default value for the removed
111 * attribute is defined in the DTD, a new attribute immediately appears
112 * with the default value as well as the corresponding namespace URI,
113 * local name, and prefix when applicable. The implementation may handle
114 * default values from other schemas similarly but applications should
115 * use <code>Document.normalizeDocument()</code> to guarantee this
116 * information is up-to-date.
117 * <br>If no attribute with this name is found, this method has no effect.
118 * <br>To remove an attribute by local name and namespace URI, use the
119 * <code>removeAttributeNS</code> method.
120 * @param name The name of the attribute to remove.
121 * @exception DOMException
122 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
123 */
124 public void removeAttribute(String name) throws DOMException;
125
126 /**
127 * Retrieves an attribute node by name.
128 * <br>To retrieve an attribute node by qualified name and namespace URI,
129 * use the <code>getAttributeNodeNS</code> method.
130 * @param name The name (<code>nodeName</code>) of the attribute to
131 * retrieve.
132 * @return The <code>Attr</code> node with the specified name (
133 * <code>nodeName</code>) or <code>null</code> if there is no such
134 * attribute.
135 */
136 public Attr getAttributeNode(String name);
137
138 /**
139 * Adds a new attribute node. If an attribute with that name (
140 * <code>nodeName</code>) is already present in the element, it is
141 * replaced by the new one. Replacing an attribute node by itself has no
142 * effect.
143 * <br>To add a new attribute node with a qualified name and namespace
144 * URI, use the <code>setAttributeNodeNS</code> method.
145 * @param newAttr The <code>Attr</code> node to add to the attribute list.
146 * @return If the <code>newAttr</code> attribute replaces an existing
147 * attribute, the replaced <code>Attr</code> node is returned,
148 * otherwise <code>null</code> is returned.
149 * @exception DOMException
150 * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
151 * different document than the one that created the element.
152 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
153 * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
154 * attribute of another <code>Element</code> object. The DOM user must
155 * explicitly clone <code>Attr</code> nodes to re-use them in other
156 * elements.
157 */
158 public Attr setAttributeNode(Attr newAttr) throws DOMException;
159
160 /**
161 * Removes the specified attribute node. If a default value for the
162 * removed <code>Attr</code> node is defined in the DTD, a new node
163 * immediately appears with the default value as well as the
164 * corresponding namespace URI, local name, and prefix when applicable.
165 * The implementation may handle default values from other schemas
166 * similarly but applications should use
167 * <code>Document.normalizeDocument()</code> to guarantee this
168 * information is up-to-date.
169 * @param oldAttr The <code>Attr</code> node to remove from the attribute
170 * list.
171 * @return The <code>Attr</code> node that was removed.
172 * @exception DOMException
173 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
174 * <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
175 * of the element.
176 */
177 public Attr removeAttributeNode(Attr oldAttr) throws DOMException;
178
179 /**
180 * Returns a <code>NodeList</code> of all descendant <code>Elements</code>
181 * with a given tag name, in document order.
182 * @param name The name of the tag to match on. The special value "*"
183 * matches all tags.
184 * @return A list of matching <code>Element</code> nodes.
185 */
186 public NodeList getElementsByTagName(String name);
187
188 /**
189 * Retrieves an attribute value by local name and namespace URI.
190 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
191 * , applications must use the value <code>null</code> as the
192 * <code>namespaceURI</code> parameter for methods if they wish to have
193 * no namespace.
194 * @param namespaceURI The namespace URI of the attribute to retrieve.
195 * @param localName The local name of the attribute to retrieve.
196 * @return The <code>Attr</code> value as a string, or the empty string
197 * if that attribute does not have a specified or default value.
198 * @exception DOMException
199 * NOT_SUPPORTED_ERR: May be raised if the implementation does not
200 * support the feature <code>"XML"</code> and the language exposed
201 * 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>]).
202 * @since DOM Level 2
203 */
204 public String getAttributeNS(String namespaceURI, String localName)
205 throws DOMException;
206
207 /**
208 * Adds a new attribute. If an attribute with the same local name and
209 * namespace URI is already present on the element, its prefix is
210 * changed to be the prefix part of the <code>qualifiedName</code>, and
211 * its value is changed to be the <code>value</code> parameter. This
212 * value is a simple string; it is not parsed as it is being set. So any
213 * markup (such as syntax to be recognized as an entity reference) is
214 * treated as literal text, and needs to be appropriately escaped by the
215 * implementation when it is written out. In order to assign an
216 * attribute value that contains entity references, the user must create
217 * an <code>Attr</code> node plus any <code>Text</code> and
218 * <code>EntityReference</code> nodes, build the appropriate subtree,
219 * and use <code>setAttributeNodeNS</code> or
220 * <code>setAttributeNode</code> to assign it as the value of an
221 * attribute.
222 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
223 * , applications must use the value <code>null</code> as the
224 * <code>namespaceURI</code> parameter for methods if they wish to have
225 * no namespace.
226 * @param namespaceURI The namespace URI of the attribute to create or
227 * alter.
228 * @param qualifiedName The qualified name of the attribute to create or
229 * alter.
230 * @param value The value to set in string form.
231 * @exception DOMException
232 * INVALID_CHARACTER_ERR: Raised if the specified qualified name is not
233 * an XML name according to the XML version in use specified in the
234 * <code>Document.xmlVersion</code> attribute.
235 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
236 * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
237 * malformed per the Namespaces in XML specification, if the
238 * <code>qualifiedName</code> has a prefix and the
239 * <code>namespaceURI</code> is <code>null</code>, if the
240 * <code>qualifiedName</code> has a prefix that is "xml" and the
241 * <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
242 * http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is "xmlns" and the
243 * <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".
244 * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
245 * support the feature <code>"XML"</code> and the language exposed
246 * 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>]).
247 * @since DOM Level 2
248 */
249 public void setAttributeNS(String namespaceURI,
250 String qualifiedName, String value) throws DOMException;
251
252 /**
253 * Removes an attribute by local name and namespace URI. If a default
254 * value for the removed attribute is defined in the DTD, a new
255 * attribute immediately appears with the default value as well as the
256 * corresponding namespace URI, local name, and prefix when applicable.
257 * The implementation may handle default values from other schemas
258 * similarly but applications should use
259 * <code>Document.normalizeDocument()</code> to guarantee this
260 * information is up-to-date.
261 * <br>If no attribute with this local name and namespace URI is found,
262 * this method has no effect.
263 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
264 * , applications must use the value <code>null</code> as the
265 * <code>namespaceURI</code> parameter for methods if they wish to have
266 * no namespace.
267 * @param namespaceURI The namespace URI of the attribute to remove.
268 * @param localName The local name of the attribute to remove.
269 * @exception DOMException
270 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
271 * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
272 * support the feature <code>"XML"</code> and the language exposed
273 * 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>]).
274 * @since DOM Level 2
275 */
276 public void removeAttributeNS(String namespaceURI, String localName)
277 throws DOMException;
278
279 /**
280 * Retrieves an <code>Attr</code> node by local name and namespace URI.
281 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
282 * , applications must use the value <code>null</code> as the
283 * <code>namespaceURI</code> parameter for methods if they wish to have
284 * no namespace.
285 * @param namespaceURI The namespace URI of the attribute to retrieve.
286 * @param localName The local name of the attribute to retrieve.
287 * @return The <code>Attr</code> node with the specified attribute local
288 * name and namespace URI or <code>null</code> if there is no such
289 * attribute.
290 * @exception DOMException
291 * NOT_SUPPORTED_ERR: May be raised if the implementation does not
292 * support the feature <code>"XML"</code> and the language exposed
293 * 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>]).
294 * @since DOM Level 2
295 */
296 public Attr getAttributeNodeNS(String namespaceURI, String localName)
297 throws DOMException;
298
299 /**
300 * Adds a new attribute. If an attribute with that local name and that
301 * namespace URI is already present in the element, it is replaced by
302 * the new one. Replacing an attribute node by itself has no effect.
303 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
304 * , applications must use the value <code>null</code> as the
305 * <code>namespaceURI</code> parameter for methods if they wish to have
306 * no namespace.
307 * @param newAttr The <code>Attr</code> node to add to the attribute list.
308 * @return If the <code>newAttr</code> attribute replaces an existing
309 * attribute with the same local name and namespace URI, the replaced
310 * <code>Attr</code> node is returned, otherwise <code>null</code> is
311 * returned.
312 * @exception DOMException
313 * WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
314 * different document than the one that created the element.
315 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
316 * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
317 * attribute of another <code>Element</code> object. The DOM user must
318 * explicitly clone <code>Attr</code> nodes to re-use them in other
319 * elements.
320 * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
321 * support the feature <code>"XML"</code> and the language exposed
322 * 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>]).
323 * @since DOM Level 2
324 */
325 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException;
326
327 /**
328 * Returns a <code>NodeList</code> of all the descendant
329 * <code>Elements</code> with a given local name and namespace URI in
330 * document order.
331 * @param namespaceURI The namespace URI of the elements to match on. The
332 * special value "*" matches all namespaces.
333 * @param localName The local name of the elements to match on. The
334 * special value "*" matches all local names.
335 * @return A new <code>NodeList</code> object containing all the matched
336 * <code>Elements</code>.
337 * @exception DOMException
338 * NOT_SUPPORTED_ERR: May be raised if the implementation does not
339 * support the feature <code>"XML"</code> and the language exposed
340 * 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>]).
341 * @since DOM Level 2
342 */
343 public NodeList getElementsByTagNameNS(String namespaceURI,
344 String localName) throws DOMException;
345
346 /**
347 * Returns <code>true</code> when an attribute with a given name is
348 * specified on this element or has a default value, <code>false</code>
349 * otherwise.
350 * @param name The name of the attribute to look for.
351 * @return <code>true</code> if an attribute with the given name is
352 * specified on this element or has a default value, <code>false</code>
353 * otherwise.
354 * @since DOM Level 2
355 */
356 public boolean hasAttribute(String name);
357
358 /**
359 * Returns <code>true</code> when an attribute with a given local name and
360 * namespace URI is specified on this element or has a default value,
361 * <code>false</code> otherwise.
362 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
363 * , applications must use the value <code>null</code> as the
364 * <code>namespaceURI</code> parameter for methods if they wish to have
365 * no namespace.
366 * @param namespaceURI The namespace URI of the attribute to look for.
367 * @param localName The local name of the attribute to look for.
368 * @return <code>true</code> if an attribute with the given local name
369 * and namespace URI is specified or has a default value on this
370 * element, <code>false</code> otherwise.
371 * @exception DOMException
372 * NOT_SUPPORTED_ERR: May be raised if the implementation does not
373 * support the feature <code>"XML"</code> and the language exposed
374 * 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>]).
375 * @since DOM Level 2
376 */
377 public boolean hasAttributeNS(String namespaceURI, String localName)
378 throws DOMException;
379
380 /**
381 * The type information associated with this element.
382 * @since DOM Level 3
383 */
384 public TypeInfo getSchemaTypeInfo();
385
386 /**
387 * If the parameter <code>isId</code> is <code>true</code>, this method
388 * declares the specified attribute to be a user-determined ID attribute
389 * . This affects the value of <code>Attr.isId</code> and the behavior
390 * of <code>Document.getElementById</code>, but does not change any
391 * schema that may be in use, in particular this does not affect the
392 * <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
393 * node. Use the value <code>false</code> for the parameter
394 * <code>isId</code> to undeclare an attribute for being a
395 * user-determined ID attribute.
396 * <br> To specify an attribute by local name and namespace URI, use the
397 * <code>setIdAttributeNS</code> method.
398 * @param name The name of the attribute.
399 * @param isId Whether the attribute is a of type ID.
400 * @exception DOMException
401 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
402 * <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
403 * of this element.
404 * @since DOM Level 3
405 */
406 public void setIdAttribute(String name, boolean isId)
407 throws DOMException;
408
409 /**
410 * If the parameter <code>isId</code> is <code>true</code>, this method
411 * declares the specified attribute to be a user-determined ID attribute
412 * . This affects the value of <code>Attr.isId</code> and the behavior
413 * of <code>Document.getElementById</code>, but does not change any
414 * schema that may be in use, in particular this does not affect the
415 * <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
416 * node. Use the value <code>false</code> for the parameter
417 * <code>isId</code> to undeclare an attribute for being a
418 * user-determined ID attribute.
419 * @param namespaceURI The namespace URI of the attribute.
420 * @param localName The local name of the attribute.
421 * @param isId Whether the attribute is a of type ID.
422 * @exception DOMException
423 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
424 * <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
425 * of this element.
426 * @since DOM Level 3
427 */
428 public void setIdAttributeNS(String namespaceURI, String localName,
429 boolean isId) throws DOMException;
430
431 /**
432 * If the parameter <code>isId</code> is <code>true</code>, this method
433 * declares the specified attribute to be a user-determined ID attribute
434 * . This affects the value of <code>Attr.isId</code> and the behavior
435 * of <code>Document.getElementById</code>, but does not change any
436 * schema that may be in use, in particular this does not affect the
437 * <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
438 * node. Use the value <code>false</code> for the parameter
439 * <code>isId</code> to undeclare an attribute for being a
440 * user-determined ID attribute.
441 * @param idAttr The attribute node.
442 * @param isId Whether the attribute is a of type ID.
443 * @exception DOMException
444 * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
445 * <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
446 * of this element.
447 * @since DOM Level 3
448 */
449 public void setIdAttributeNode(Attr idAttr, boolean isId)
450 throws DOMException;
451
452 }
|