Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="dom-nodelist-objects.html" /> | |
13 | <link rel="prev" href="dom-implementation-objects.html" /> | |
14 | <link rel="parent" href="node652.html" /> | |
15 | <link rel="next" href="dom-nodelist-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>13.6.2.2 Node Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="13.6.2.1 DOMImplementation Objects" | |
25 | href="dom-implementation-objects.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="13.6.2 Objects in the" | |
28 | href="node652.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="13.6.2.3 NodeList Objects" | |
31 | href="dom-nodelist-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="dom-implementation-objects.html">13.6.2.1 DOMImplementation Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="node652.html">13.6.2 Objects in the</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="dom-nodelist-objects.html">13.6.2.3 NodeList Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H3><A NAME="SECTION0015622000000000000000"></A><A NAME="dom-node-objects"></A> | |
56 | <BR> | |
57 | 13.6.2.2 Node Objects | |
58 | </H3> | |
59 | ||
60 | <P> | |
61 | All of the components of an XML document are subclasses of | |
62 | <tt class="class">Node</tt>. | |
63 | ||
64 | <P> | |
65 | <dl><dt><b><tt id='l2h-4363' xml:id='l2h-4363' class="member">nodeType</tt></b></dt> | |
66 | <dd> | |
67 | An integer representing the node type. Symbolic constants for the | |
68 | types are on the <tt class="class">Node</tt> object: | |
69 | <tt class="constant">ELEMENT_NODE</tt>, <tt class="constant">ATTRIBUTE_NODE</tt>, | |
70 | <tt class="constant">TEXT_NODE</tt>, <tt class="constant">CDATA_SECTION_NODE</tt>, | |
71 | <tt class="constant">ENTITY_NODE</tt>, <tt class="constant">PROCESSING_INSTRUCTION_NODE</tt>, | |
72 | <tt class="constant">COMMENT_NODE</tt>, <tt class="constant">DOCUMENT_NODE</tt>, | |
73 | <tt class="constant">DOCUMENT_TYPE_NODE</tt>, <tt class="constant">NOTATION_NODE</tt>. | |
74 | This is a read-only attribute. | |
75 | </dl> | |
76 | ||
77 | <P> | |
78 | <dl><dt><b><tt id='l2h-4364' xml:id='l2h-4364' class="member">parentNode</tt></b></dt> | |
79 | <dd> | |
80 | The parent of the current node, or <code>None</code> for the document node. | |
81 | The value is always a <tt class="class">Node</tt> object or <code>None</code>. For | |
82 | <tt class="class">Element</tt> nodes, this will be the parent element, except for the | |
83 | root element, in which case it will be the <tt class="class">Document</tt> object. | |
84 | For <tt class="class">Attr</tt> nodes, this is always <code>None</code>. | |
85 | This is a read-only attribute. | |
86 | </dl> | |
87 | ||
88 | <P> | |
89 | <dl><dt><b><tt id='l2h-4365' xml:id='l2h-4365' class="member">attributes</tt></b></dt> | |
90 | <dd> | |
91 | A <tt class="class">NamedNodeMap</tt> of attribute objects. Only elements have | |
92 | actual values for this; others provide <code>None</code> for this attribute. | |
93 | This is a read-only attribute. | |
94 | </dl> | |
95 | ||
96 | <P> | |
97 | <dl><dt><b><tt id='l2h-4366' xml:id='l2h-4366' class="member">previousSibling</tt></b></dt> | |
98 | <dd> | |
99 | The node that immediately precedes this one with the same parent. For | |
100 | instance the element with an end-tag that comes just before the | |
101 | <var>self</var> element's start-tag. Of course, XML documents are made | |
102 | up of more than just elements so the previous sibling could be text, a | |
103 | comment, or something else. If this node is the first child of the | |
104 | parent, this attribute will be <code>None</code>. | |
105 | This is a read-only attribute. | |
106 | </dl> | |
107 | ||
108 | <P> | |
109 | <dl><dt><b><tt id='l2h-4367' xml:id='l2h-4367' class="member">nextSibling</tt></b></dt> | |
110 | <dd> | |
111 | The node that immediately follows this one with the same parent. See | |
112 | also <tt class="member">previousSibling</tt>. If this is the last child of the | |
113 | parent, this attribute will be <code>None</code>. | |
114 | This is a read-only attribute. | |
115 | </dl> | |
116 | ||
117 | <P> | |
118 | <dl><dt><b><tt id='l2h-4368' xml:id='l2h-4368' class="member">childNodes</tt></b></dt> | |
119 | <dd> | |
120 | A list of nodes contained within this node. | |
121 | This is a read-only attribute. | |
122 | </dl> | |
123 | ||
124 | <P> | |
125 | <dl><dt><b><tt id='l2h-4369' xml:id='l2h-4369' class="member">firstChild</tt></b></dt> | |
126 | <dd> | |
127 | The first child of the node, if there are any, or <code>None</code>. | |
128 | This is a read-only attribute. | |
129 | </dl> | |
130 | ||
131 | <P> | |
132 | <dl><dt><b><tt id='l2h-4370' xml:id='l2h-4370' class="member">lastChild</tt></b></dt> | |
133 | <dd> | |
134 | The last child of the node, if there are any, or <code>None</code>. | |
135 | This is a read-only attribute. | |
136 | </dl> | |
137 | ||
138 | <P> | |
139 | <dl><dt><b><tt id='l2h-4371' xml:id='l2h-4371' class="member">localName</tt></b></dt> | |
140 | <dd> | |
141 | The part of the <tt class="member">tagName</tt> following the colon if there is one, | |
142 | else the entire <tt class="member">tagName</tt>. The value is a string. | |
143 | </dl> | |
144 | ||
145 | <P> | |
146 | <dl><dt><b><tt id='l2h-4372' xml:id='l2h-4372' class="member">prefix</tt></b></dt> | |
147 | <dd> | |
148 | The part of the <tt class="member">tagName</tt> preceding the colon if there is one, | |
149 | else the empty string. The value is a string, or <code>None</code> | |
150 | </dl> | |
151 | ||
152 | <P> | |
153 | <dl><dt><b><tt id='l2h-4373' xml:id='l2h-4373' class="member">namespaceURI</tt></b></dt> | |
154 | <dd> | |
155 | The namespace associated with the element name. This will be a | |
156 | string or <code>None</code>. This is a read-only attribute. | |
157 | </dl> | |
158 | ||
159 | <P> | |
160 | <dl><dt><b><tt id='l2h-4374' xml:id='l2h-4374' class="member">nodeName</tt></b></dt> | |
161 | <dd> | |
162 | This has a different meaning for each node type; see the DOM | |
163 | specification for details. You can always get the information you | |
164 | would get here from another property such as the <tt class="member">tagName</tt> | |
165 | property for elements or the <tt class="member">name</tt> property for attributes. | |
166 | For all node types, the value of this attribute will be either a | |
167 | string or <code>None</code>. This is a read-only attribute. | |
168 | </dl> | |
169 | ||
170 | <P> | |
171 | <dl><dt><b><tt id='l2h-4375' xml:id='l2h-4375' class="member">nodeValue</tt></b></dt> | |
172 | <dd> | |
173 | This has a different meaning for each node type; see the DOM | |
174 | specification for details. The situation is similar to that with | |
175 | <tt class="member">nodeName</tt>. The value is a string or <code>None</code>. | |
176 | </dl> | |
177 | ||
178 | <P> | |
179 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
180 | <td><nobr><b><tt id='l2h-4376' xml:id='l2h-4376' class="method">hasAttributes</tt></b>(</nobr></td> | |
181 | <td><var></var>)</td></tr></table></dt> | |
182 | <dd> | |
183 | Returns true if the node has any attributes. | |
184 | </dl> | |
185 | ||
186 | <P> | |
187 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
188 | <td><nobr><b><tt id='l2h-4377' xml:id='l2h-4377' class="method">hasChildNodes</tt></b>(</nobr></td> | |
189 | <td><var></var>)</td></tr></table></dt> | |
190 | <dd> | |
191 | Returns true if the node has any child nodes. | |
192 | </dl> | |
193 | ||
194 | <P> | |
195 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
196 | <td><nobr><b><tt id='l2h-4378' xml:id='l2h-4378' class="method">isSameNode</tt></b>(</nobr></td> | |
197 | <td><var>other</var>)</td></tr></table></dt> | |
198 | <dd> | |
199 | Returns true if <var>other</var> refers to the same node as this node. | |
200 | This is especially useful for DOM implementations which use any sort | |
201 | of proxy architecture (because more than one object can refer to the | |
202 | same node). | |
203 | ||
204 | <P> | |
205 | <div class="note"><b class="label">Note:</b> | |
206 | This is based on a proposed DOM Level 3 API which is still in the | |
207 | ``working draft'' stage, but this particular interface appears | |
208 | uncontroversial. Changes from the W3C will not necessarily affect | |
209 | this method in the Python DOM interface (though any new W3C API for | |
210 | this would also be supported). | |
211 | </div> | |
212 | </dl> | |
213 | ||
214 | <P> | |
215 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
216 | <td><nobr><b><tt id='l2h-4379' xml:id='l2h-4379' class="method">appendChild</tt></b>(</nobr></td> | |
217 | <td><var>newChild</var>)</td></tr></table></dt> | |
218 | <dd> | |
219 | Add a new child node to this node at the end of the list of children, | |
220 | returning <var>newChild</var>. | |
221 | </dl> | |
222 | ||
223 | <P> | |
224 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
225 | <td><nobr><b><tt id='l2h-4380' xml:id='l2h-4380' class="method">insertBefore</tt></b>(</nobr></td> | |
226 | <td><var>newChild, refChild</var>)</td></tr></table></dt> | |
227 | <dd> | |
228 | Insert a new child node before an existing child. It must be the case | |
229 | that <var>refChild</var> is a child of this node; if not, | |
230 | <tt class="exception">ValueError</tt> is raised. <var>newChild</var> is returned. If | |
231 | <var>refChild</var> is <code>None</code>, it inserts <var>newChild</var> at the end of | |
232 | the children's list. | |
233 | </dl> | |
234 | ||
235 | <P> | |
236 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
237 | <td><nobr><b><tt id='l2h-4381' xml:id='l2h-4381' class="method">removeChild</tt></b>(</nobr></td> | |
238 | <td><var>oldChild</var>)</td></tr></table></dt> | |
239 | <dd> | |
240 | Remove a child node. <var>oldChild</var> must be a child of this node; if | |
241 | not, <tt class="exception">ValueError</tt> is raised. <var>oldChild</var> is returned on | |
242 | success. If <var>oldChild</var> will not be used further, its | |
243 | <tt class="method">unlink()</tt> method should be called. | |
244 | </dl> | |
245 | ||
246 | <P> | |
247 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
248 | <td><nobr><b><tt id='l2h-4382' xml:id='l2h-4382' class="method">replaceChild</tt></b>(</nobr></td> | |
249 | <td><var>newChild, oldChild</var>)</td></tr></table></dt> | |
250 | <dd> | |
251 | Replace an existing node with a new node. It must be the case that | |
252 | <var>oldChild</var> is a child of this node; if not, | |
253 | <tt class="exception">ValueError</tt> is raised. | |
254 | </dl> | |
255 | ||
256 | <P> | |
257 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
258 | <td><nobr><b><tt id='l2h-4383' xml:id='l2h-4383' class="method">normalize</tt></b>(</nobr></td> | |
259 | <td><var></var>)</td></tr></table></dt> | |
260 | <dd> | |
261 | Join adjacent text nodes so that all stretches of text are stored as | |
262 | single <tt class="class">Text</tt> instances. This simplifies processing text from a | |
263 | DOM tree for many applications. | |
264 | ||
265 | <span class="versionnote">New in version 2.1.</span> | |
266 | ||
267 | </dl> | |
268 | ||
269 | <P> | |
270 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
271 | <td><nobr><b><tt id='l2h-4384' xml:id='l2h-4384' class="method">cloneNode</tt></b>(</nobr></td> | |
272 | <td><var>deep</var>)</td></tr></table></dt> | |
273 | <dd> | |
274 | Clone this node. Setting <var>deep</var> means to clone all child nodes as | |
275 | well. This returns the clone. | |
276 | </dl> | |
277 | ||
278 | <P> | |
279 | ||
280 | <DIV CLASS="navigation"> | |
281 | <div class='online-navigation'> | |
282 | <p></p><hr /> | |
283 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
284 | <tr> | |
285 | <td class='online-navigation'><a rel="prev" title="13.6.2.1 DOMImplementation Objects" | |
286 | href="dom-implementation-objects.html"><img src='../icons/previous.png' | |
287 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
288 | <td class='online-navigation'><a rel="parent" title="13.6.2 Objects in the" | |
289 | href="node652.html"><img src='../icons/up.png' | |
290 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
291 | <td class='online-navigation'><a rel="next" title="13.6.2.3 NodeList Objects" | |
292 | href="dom-nodelist-objects.html"><img src='../icons/next.png' | |
293 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
294 | <td align="center" width="100%">Python Library Reference</td> | |
295 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
296 | href="contents.html"><img src='../icons/contents.png' | |
297 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
298 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
299 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
300 | <td class='online-navigation'><a rel="index" title="Index" | |
301 | href="genindex.html"><img src='../icons/index.png' | |
302 | border='0' height='32' alt='Index' width='32' /></A></td> | |
303 | </tr></table> | |
304 | <div class='online-navigation'> | |
305 | <b class="navlabel">Previous:</b> | |
306 | <a class="sectref" rel="prev" href="dom-implementation-objects.html">13.6.2.1 DOMImplementation Objects</A> | |
307 | <b class="navlabel">Up:</b> | |
308 | <a class="sectref" rel="parent" href="node652.html">13.6.2 Objects in the</A> | |
309 | <b class="navlabel">Next:</b> | |
310 | <a class="sectref" rel="next" href="dom-nodelist-objects.html">13.6.2.3 NodeList Objects</A> | |
311 | </div> | |
312 | </div> | |
313 | <hr /> | |
314 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
315 | </DIV> | |
316 | <!--End of Navigation Panel--> | |
317 | <ADDRESS> | |
318 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
319 | </ADDRESS> | |
320 | </BODY> | |
321 | </HTML> |