Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.xml/share/classes/org/w3c/dom/Element.java
40948 views
1
/*
2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
*
4
* This code is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 2 only, as
6
* published by the Free Software Foundation. Oracle designates this
7
* particular file as subject to the "Classpath" exception as provided
8
* by Oracle in the LICENSE file that accompanied this code.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
/*
26
* This file is available under and governed by the GNU General Public
27
* License version 2 only, as published by the Free Software Foundation.
28
* However, the following notice accompanied the original version of this
29
* file and, per its terms, should not be removed:
30
*
31
* Copyright (c) 2004 World Wide Web Consortium,
32
*
33
* (Massachusetts Institute of Technology, European Research Consortium for
34
* Informatics and Mathematics, Keio University). All Rights Reserved. This
35
* work is distributed under the W3C(r) Software License [1] in the hope that
36
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
37
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38
*
39
* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
40
*/
41
42
package org.w3c.dom;
43
44
/**
45
* The <code>Element</code> interface represents an element in an HTML or XML
46
* document. Elements may have attributes associated with them; since the
47
* <code>Element</code> interface inherits from <code>Node</code>, the
48
* generic <code>Node</code> interface attribute <code>attributes</code> may
49
* be used to retrieve the set of all attributes for an element. There are
50
* methods on the <code>Element</code> interface to retrieve either an
51
* <code>Attr</code> object by name or an attribute value by name. In XML,
52
* where an attribute value may contain entity references, an
53
* <code>Attr</code> object should be retrieved to examine the possibly
54
* fairly complex sub-tree representing the attribute value. On the other
55
* hand, in HTML, where all attributes have simple string values, methods to
56
* directly access an attribute value can safely be used as a convenience.
57
* <p ><b>Note:</b> In DOM Level 2, the method <code>normalize</code> is
58
* inherited from the <code>Node</code> interface where it was moved.
59
* <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>.
60
*/
61
public interface Element extends Node {
62
/**
63
* The name of the element. If <code>Node.localName</code> is different
64
* from <code>null</code>, this attribute is a qualified name. For
65
* example, in:
66
* <pre> &lt;elementExample id="demo"&gt; ...
67
* &lt;/elementExample&gt; , </pre>
68
* <code>tagName</code> has the value
69
* <code>"elementExample"</code>. Note that this is case-preserving in
70
* XML, as are all of the operations of the DOM. The HTML DOM returns
71
* the <code>tagName</code> of an HTML element in the canonical
72
* uppercase form, regardless of the case in the source HTML document.
73
*/
74
public String getTagName();
75
76
/**
77
* Retrieves an attribute value by name.
78
* @param name The name of the attribute to retrieve.
79
* @return The <code>Attr</code> value as a string, or the empty string
80
* if that attribute does not have a specified or default value.
81
*/
82
public String getAttribute(String name);
83
84
/**
85
* Adds a new attribute. If an attribute with that name is already present
86
* in the element, its value is changed to be that of the value
87
* parameter. This value is a simple string; it is not parsed as it is
88
* being set. So any markup (such as syntax to be recognized as an
89
* entity reference) is treated as literal text, and needs to be
90
* appropriately escaped by the implementation when it is written out.
91
* In order to assign an attribute value that contains entity
92
* references, the user must create an <code>Attr</code> node plus any
93
* <code>Text</code> and <code>EntityReference</code> nodes, build the
94
* appropriate subtree, and use <code>setAttributeNode</code> to assign
95
* it as the value of an attribute.
96
* <br>To set an attribute with a qualified name and namespace URI, use
97
* the <code>setAttributeNS</code> method.
98
* @param name The name of the attribute to create or alter.
99
* @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,
107
String value)
108
throws DOMException;
109
110
/**
111
* Removes an attribute by name. If a default value for the removed
112
* attribute is defined in the DTD, a new attribute immediately appears
113
* with the default value as well as the corresponding namespace URI,
114
* local name, and prefix when applicable. The implementation may handle
115
* default values from other schemas similarly but applications should
116
* use <code>Document.normalizeDocument()</code> to guarantee this
117
* information is up-to-date.
118
* <br>If no attribute with this name is found, this method has no effect.
119
* <br>To remove an attribute by local name and namespace URI, use the
120
* <code>removeAttributeNS</code> method.
121
* @param name The name of the attribute to remove.
122
* @exception DOMException
123
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
124
*/
125
public void removeAttribute(String name)
126
throws DOMException;
127
128
/**
129
* Retrieves an attribute node by name.
130
* <br>To retrieve an attribute node by qualified name and namespace URI,
131
* use the <code>getAttributeNodeNS</code> method.
132
* @param name The name (<code>nodeName</code>) of the attribute to
133
* retrieve.
134
* @return The <code>Attr</code> node with the specified name (
135
* <code>nodeName</code>) or <code>null</code> if there is no such
136
* attribute.
137
*/
138
public Attr getAttributeNode(String name);
139
140
/**
141
* Adds a new attribute node. If an attribute with that name (
142
* <code>nodeName</code>) is already present in the element, it is
143
* replaced by the new one. Replacing an attribute node by itself has no
144
* effect.
145
* <br>To add a new attribute node with a qualified name and namespace
146
* URI, use the <code>setAttributeNodeNS</code> method.
147
* @param newAttr The <code>Attr</code> node to add to the attribute list.
148
* @return If the <code>newAttr</code> attribute replaces an existing
149
* attribute, the replaced <code>Attr</code> node is returned,
150
* otherwise <code>null</code> is returned.
151
* @exception DOMException
152
* WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
153
* different document than the one that created the element.
154
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
155
* <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
156
* attribute of another <code>Element</code> object. The DOM user must
157
* explicitly clone <code>Attr</code> nodes to re-use them in other
158
* elements.
159
*/
160
public Attr setAttributeNode(Attr newAttr)
161
throws DOMException;
162
163
/**
164
* Removes the specified attribute node. If a default value for the
165
* removed <code>Attr</code> node is defined in the DTD, a new node
166
* immediately appears with the default value as well as the
167
* corresponding namespace URI, local name, and prefix when applicable.
168
* The implementation may handle default values from other schemas
169
* similarly but applications should use
170
* <code>Document.normalizeDocument()</code> to guarantee this
171
* information is up-to-date.
172
* @param oldAttr The <code>Attr</code> node to remove from the attribute
173
* list.
174
* @return The <code>Attr</code> node that was removed.
175
* @exception DOMException
176
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
177
* <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
178
* of the element.
179
*/
180
public Attr removeAttributeNode(Attr oldAttr)
181
throws DOMException;
182
183
/**
184
* Returns a <code>NodeList</code> of all descendant <code>Elements</code>
185
* with a given tag name, in document order.
186
* @param name The name of the tag to match on. The special value "*"
187
* matches all tags.
188
* @return A list of matching <code>Element</code> nodes.
189
*/
190
public NodeList getElementsByTagName(String name);
191
192
/**
193
* Retrieves an attribute value by local name and namespace URI.
194
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
195
* , applications must use the value <code>null</code> as the
196
* <code>namespaceURI</code> parameter for methods if they wish to have
197
* no namespace.
198
* @param namespaceURI The namespace URI of the attribute to retrieve.
199
* @param localName The local name of the attribute to retrieve.
200
* @return The <code>Attr</code> value as a string, or the empty string
201
* if that attribute does not have a specified or default value.
202
* @exception DOMException
203
* NOT_SUPPORTED_ERR: May be raised if the implementation does not
204
* support the feature <code>"XML"</code> and the language exposed
205
* 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>]).
206
* @since 1.4, DOM Level 2
207
*/
208
public String getAttributeNS(String namespaceURI,
209
String localName)
210
throws DOMException;
211
212
/**
213
* Adds a new attribute. If an attribute with the same local name and
214
* namespace URI is already present on the element, its prefix is
215
* changed to be the prefix part of the <code>qualifiedName</code>, and
216
* its value is changed to be the <code>value</code> parameter. This
217
* value is a simple string; it is not parsed as it is being set. So any
218
* markup (such as syntax to be recognized as an entity reference) is
219
* treated as literal text, and needs to be appropriately escaped by the
220
* implementation when it is written out. In order to assign an
221
* attribute value that contains entity references, the user must create
222
* an <code>Attr</code> node plus any <code>Text</code> and
223
* <code>EntityReference</code> nodes, build the appropriate subtree,
224
* and use <code>setAttributeNodeNS</code> or
225
* <code>setAttributeNode</code> to assign it as the value of an
226
* attribute.
227
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
228
* , applications must use the value <code>null</code> as the
229
* <code>namespaceURI</code> parameter for methods if they wish to have
230
* no namespace.
231
* @param namespaceURI The namespace URI of the attribute to create or
232
* alter.
233
* @param qualifiedName The qualified name of the attribute to create or
234
* alter.
235
* @param value The value to set in string form.
236
* @exception DOMException
237
* INVALID_CHARACTER_ERR: Raised if the specified qualified name is not
238
* an XML name according to the XML version in use specified in the
239
* <code>Document.xmlVersion</code> attribute.
240
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
241
* <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
242
* malformed per the Namespaces in XML specification, if the
243
* <code>qualifiedName</code> has a prefix and the
244
* <code>namespaceURI</code> is <code>null</code>, if the
245
* <code>qualifiedName</code> has a prefix that is "xml" and the
246
* <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
247
* http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is "xmlns" and the
248
* <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".
249
* <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
250
* support the feature <code>"XML"</code> and the language exposed
251
* 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>]).
252
* @since 1.4, DOM Level 2
253
*/
254
public void setAttributeNS(String namespaceURI,
255
String qualifiedName,
256
String value)
257
throws DOMException;
258
259
/**
260
* Removes an attribute by local name and namespace URI. If a default
261
* value for the removed attribute is defined in the DTD, a new
262
* attribute immediately appears with the default value as well as the
263
* corresponding namespace URI, local name, and prefix when applicable.
264
* The implementation may handle default values from other schemas
265
* similarly but applications should use
266
* <code>Document.normalizeDocument()</code> to guarantee this
267
* information is up-to-date.
268
* <br>If no attribute with this local name and namespace URI is found,
269
* this method has no effect.
270
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
271
* , applications must use the value <code>null</code> as the
272
* <code>namespaceURI</code> parameter for methods if they wish to have
273
* no namespace.
274
* @param namespaceURI The namespace URI of the attribute to remove.
275
* @param localName The local name of the attribute to remove.
276
* @exception DOMException
277
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
278
* <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
279
* support the feature <code>"XML"</code> and the language exposed
280
* 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>]).
281
* @since 1.4, DOM Level 2
282
*/
283
public void removeAttributeNS(String namespaceURI,
284
String localName)
285
throws DOMException;
286
287
/**
288
* Retrieves an <code>Attr</code> node by local name and namespace URI.
289
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
290
* , applications must use the value <code>null</code> as the
291
* <code>namespaceURI</code> parameter for methods if they wish to have
292
* no namespace.
293
* @param namespaceURI The namespace URI of the attribute to retrieve.
294
* @param localName The local name of the attribute to retrieve.
295
* @return The <code>Attr</code> node with the specified attribute local
296
* name and namespace URI or <code>null</code> if there is no such
297
* attribute.
298
* @exception DOMException
299
* NOT_SUPPORTED_ERR: May be raised if the implementation does not
300
* support the feature <code>"XML"</code> and the language exposed
301
* 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>]).
302
* @since 1.4, DOM Level 2
303
*/
304
public Attr getAttributeNodeNS(String namespaceURI,
305
String localName)
306
throws DOMException;
307
308
/**
309
* Adds a new attribute. If an attribute with that local name and that
310
* namespace URI is already present in the element, it is replaced by
311
* the new one. Replacing an attribute node by itself has no effect.
312
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
313
* , applications must use the value <code>null</code> as the
314
* <code>namespaceURI</code> parameter for methods if they wish to have
315
* no namespace.
316
* @param newAttr The <code>Attr</code> node to add to the attribute list.
317
* @return If the <code>newAttr</code> attribute replaces an existing
318
* attribute with the same local name and namespace URI, the replaced
319
* <code>Attr</code> node is returned, otherwise <code>null</code> is
320
* returned.
321
* @exception DOMException
322
* WRONG_DOCUMENT_ERR: Raised if <code>newAttr</code> was created from a
323
* different document than the one that created the element.
324
* <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
325
* <br>INUSE_ATTRIBUTE_ERR: Raised if <code>newAttr</code> is already an
326
* attribute of another <code>Element</code> object. The DOM user must
327
* explicitly clone <code>Attr</code> nodes to re-use them in other
328
* elements.
329
* <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
330
* support the feature <code>"XML"</code> and the language exposed
331
* 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>]).
332
* @since 1.4, DOM Level 2
333
*/
334
public Attr setAttributeNodeNS(Attr newAttr)
335
throws DOMException;
336
337
/**
338
* Returns a <code>NodeList</code> of all the descendant
339
* <code>Elements</code> with a given local name and namespace URI in
340
* document order.
341
* @param namespaceURI The namespace URI of the elements to match on. The
342
* special value "*" matches all namespaces.
343
* @param localName The local name of the elements to match on. The
344
* special value "*" matches all local names.
345
* @return A new <code>NodeList</code> object containing all the matched
346
* <code>Elements</code>.
347
* @exception DOMException
348
* NOT_SUPPORTED_ERR: May be raised if the implementation does not
349
* support the feature <code>"XML"</code> and the language exposed
350
* 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>]).
351
* @since 1.4, DOM Level 2
352
*/
353
public NodeList getElementsByTagNameNS(String namespaceURI,
354
String localName)
355
throws DOMException;
356
357
/**
358
* Returns <code>true</code> when an attribute with a given name is
359
* specified on this element or has a default value, <code>false</code>
360
* otherwise.
361
* @param name The name of the attribute to look for.
362
* @return <code>true</code> if an attribute with the given name is
363
* specified on this element or has a default value, <code>false</code>
364
* otherwise.
365
* @since 1.4, DOM Level 2
366
*/
367
public boolean hasAttribute(String name);
368
369
/**
370
* Returns <code>true</code> when an attribute with a given local name and
371
* namespace URI is specified on this element or has a default value,
372
* <code>false</code> otherwise.
373
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
374
* , applications must use the value <code>null</code> as the
375
* <code>namespaceURI</code> parameter for methods if they wish to have
376
* no namespace.
377
* @param namespaceURI The namespace URI of the attribute to look for.
378
* @param localName The local name of the attribute to look for.
379
* @return <code>true</code> if an attribute with the given local name
380
* and namespace URI is specified or has a default value on this
381
* element, <code>false</code> otherwise.
382
* @exception DOMException
383
* NOT_SUPPORTED_ERR: May be raised if the implementation does not
384
* support the feature <code>"XML"</code> and the language exposed
385
* 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>]).
386
* @since 1.4, DOM Level 2
387
*/
388
public boolean hasAttributeNS(String namespaceURI,
389
String localName)
390
throws DOMException;
391
392
/**
393
* The type information associated with this element.
394
* @since 1.5, DOM Level 3
395
*/
396
public TypeInfo getSchemaTypeInfo();
397
398
/**
399
* If the parameter <code>isId</code> is <code>true</code>, this method
400
* declares the specified attribute to be a user-determined ID attribute
401
* . This affects the value of <code>Attr.isId</code> and the behavior
402
* of <code>Document.getElementById</code>, but does not change any
403
* schema that may be in use, in particular this does not affect the
404
* <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
405
* node. Use the value <code>false</code> for the parameter
406
* <code>isId</code> to undeclare an attribute for being a
407
* user-determined ID attribute.
408
* <br> To specify an attribute by local name and namespace URI, use the
409
* <code>setIdAttributeNS</code> method.
410
* @param name The name of the attribute.
411
* @param isId Whether the attribute is a of type ID.
412
* @exception DOMException
413
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
414
* <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
415
* of this element.
416
* @since 1.5, DOM Level 3
417
*/
418
public void setIdAttribute(String name,
419
boolean isId)
420
throws DOMException;
421
422
/**
423
* If the parameter <code>isId</code> is <code>true</code>, this method
424
* declares the specified attribute to be a user-determined ID attribute
425
* . This affects the value of <code>Attr.isId</code> and the behavior
426
* of <code>Document.getElementById</code>, but does not change any
427
* schema that may be in use, in particular this does not affect the
428
* <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
429
* node. Use the value <code>false</code> for the parameter
430
* <code>isId</code> to undeclare an attribute for being a
431
* user-determined ID attribute.
432
* @param namespaceURI The namespace URI of the attribute.
433
* @param localName The local name of the attribute.
434
* @param isId Whether the attribute is a of type ID.
435
* @exception DOMException
436
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
437
* <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
438
* of this element.
439
* @since 1.5, DOM Level 3
440
*/
441
public void setIdAttributeNS(String namespaceURI,
442
String localName,
443
boolean isId)
444
throws DOMException;
445
446
/**
447
* If the parameter <code>isId</code> is <code>true</code>, this method
448
* declares the specified attribute to be a user-determined ID attribute
449
* . This affects the value of <code>Attr.isId</code> and the behavior
450
* of <code>Document.getElementById</code>, but does not change any
451
* schema that may be in use, in particular this does not affect the
452
* <code>Attr.schemaTypeInfo</code> of the specified <code>Attr</code>
453
* node. Use the value <code>false</code> for the parameter
454
* <code>isId</code> to undeclare an attribute for being a
455
* user-determined ID attribute.
456
* @param idAttr The attribute node.
457
* @param isId Whether the attribute is a of type ID.
458
* @exception DOMException
459
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
460
* <br>NOT_FOUND_ERR: Raised if the specified node is not an attribute
461
* of this element.
462
* @since 1.5, DOM Level 3
463
*/
464
public void setIdAttributeNode(Attr idAttr,
465
boolean isId)
466
throws DOMException;
467
468
}
469
470