@@ -89,17 +89,22 @@ \section{\module{xml.dom} ---
8989\subsection {Objects in the DOM \label {dom-objects } }
9090
9191The definitive documentation for the DOM is the DOM specification from
92- the W3C. This section lists the properties and methods supported by
93- \refmodule {xml.dom.minidom}.
92+ the W3C.
9493
9594Note that DOM attributes may also be manipulated as nodes instead of
9695as simple strings. It is fairly rare that you must do this, however,
9796so this usage is not yet documented.
9897
9998
10099\begin {tableiii }{l|l|l}{class}{Interface}{Section}{Purpose}
100+ \lineiii {DOMImplementation}{\ref {dom-implementation-objects }}
101+ {Interface to the underlying implementation.}
101102 \lineiii {Node}{\ref {dom-node-objects }}
102103 {Base interface for most objects in a document.}
104+ \lineiii {NodeList}{\ref {dom-nodelist-objects }}
105+ {Interface for a sequence of nodes.}
106+ \lineiii {DocumentType}{\ref {dom-documenttype-objects }}
107+ {Information about the declarations needed to process a document.}
103108 \lineiii {Document}{\ref {dom-document-objects }}
104109 {Object which represents an entire document.}
105110 \lineiii {Element}{\ref {dom-element-objects }}
@@ -115,6 +120,19 @@ \subsection{Objects in the DOM \label{dom-objects}}
115120\end {tableiii }
116121
117122
123+ \subsubsection {DOMImplementation Objects
124+ \label {dom-implementation-objects } }
125+
126+ The \class {DOMImplementation} interface provides a way for
127+ applications to determine the availability of particular features in
128+ the DOM they are using. DOM Level 2 added the ability to create new
129+ \class {Document} and \class {DocumentType} objects using the
130+ \class {DOMImplementation} as well.
131+
132+ \begin {methoddesc }[DOMImplementation]{hasFeature}{feature, version}
133+ \end {methoddesc }
134+
135+
118136\subsubsection {Node Objects \label {dom-node-objects } }
119137
120138All of the components of an XML document are subclasses of
@@ -131,7 +149,11 @@ \subsubsection{Node Objects \label{dom-node-objects}}
131149\end {memberdesc }
132150
133151\begin {memberdesc }[Node]{parentNode}
134- The parent of the current node. \code {None} for the document node.
152+ The parent of the current node, or \code {None} for the document node.
153+ The value is always a \class {Node} object or \code {None}. For
154+ \class {Element} nodes, this will be the parent element, except for the
155+ root element, in which case it will be the \class {Document} object.
156+ For \class {Attr} nodes, this is always \code {None}.
135157\end {memberdesc }
136158
137159\begin {memberdesc }[Node]{attributes}
@@ -144,12 +166,14 @@ \subsubsection{Node Objects \label{dom-node-objects}}
144166instance the element with an end-tag that comes just before the
145167\var {self} element's start-tag. Of course, XML documents are made
146168up of more than just elements so the previous sibling could be text, a
147- comment, or something else.
169+ comment, or something else. If this node is the first child of the
170+ parent, this attribute will be \code {None}.
148171\end {memberdesc }
149172
150173\begin {memberdesc }[Node]{nextSibling}
151174The node that immediately follows this one with the same parent. See
152- also \member {previousSibling}.
175+ also \member {previousSibling}. If this is the last child of the
176+ parent, this attribute will be \code {None}.
153177\end {memberdesc }
154178
155179\begin {memberdesc }[Node]{childNodes}
@@ -164,11 +188,18 @@ \subsubsection{Node Objects \label{dom-node-objects}}
164188The last child of the node, if there are any, or \code {None}.
165189\end {memberdesc }
166190
191+ \begin {memberdesc }[Element]{namespaceURI}
192+ The namespace associated with the element name. This will be a
193+ string.
194+ \end {memberdesc }
195+
167196\begin {memberdesc }[Node]{nodeName}
168197Has a different meaning for each node type. See the DOM specification
169198for details. You can always get the information you would get here
170199from another property such as the \member {tagName} property for
171- elements or the \member {name} property for attributes.
200+ elements or the \member {name} property for attributes. For all node
201+ types, the value of this attribute will be either a string or
202+ \code {None}.
172203\end {memberdesc }
173204
174205\begin {memberdesc }[Node]{nodeValue}
@@ -213,13 +244,91 @@ \subsubsection{Node Objects \label{dom-node-objects}}
213244
214245\begin {methoddesc }[Node]{cloneNode}{deep}
215246Clone this node. Setting \var {deep} means to clone all child nodes as
216- well.
247+ well. This returns the clone.
248+ \end {methoddesc }
249+
250+
251+ \subsubsection {NodeList Objects \label {dom-nodelist-objects } }
252+
253+ A \class {NodeList} represents a sequence of nodes. These objects are
254+ used in two ways in the DOM Core recommendation: the
255+ \class {Element} objects provides one as it's list of child nodes, and
256+ the \method {getElementsByTagName()} and
257+ \method {getElementsByTagNameNS()} methods of \class {Node} return
258+ objects with this interface to represent query results.
217259
218- \strong {Warning:} Although this method was present in the version of
219- \refmodule {xml.dom.minidom} packaged with Python 2.0, it was seriously
220- broken. This has been corrected for subsequent releases.
260+ The DOM Level 2 recommendation defines one method and one attribute
261+ for these objects:
262+
263+ \begin {methoddesc }[NodeList]{item}{i}
264+ Return the \var {i}'th item from the sequence, if there is one, or
265+ \code {None}. The index \var {i} is not allowed to be less then zero
266+ or greater than or equal to the length of the sequence.
221267\end {methoddesc }
222268
269+ \begin {memberdesc }[NodeList]{length}
270+ The number of nodes in the sequence.
271+ \end {memberdesc }
272+
273+ In addition, the Python DOM interface requires that some additional
274+ support is provided to allow \class {NodeList} objects to be used as
275+ Python sequences. All \class {NodeList} implementations must include
276+ support for \method {__len__()} and \method {__getitem__()}; this allows
277+ iteration over the \class {NodeList} in \keyword {for} statements and
278+ proper support for the \function {len()} built-in function.
279+
280+ If a DOM implementation supports modification of the document, the
281+ \class {NodeList} implementation must also support the
282+ \method {__setitem__()} and \method {__delitem__()} methods.
283+
284+
285+ \subsubsection {DocumentType Objects \label {dom-documenttype-objects } }
286+
287+ Information about the notations and entities declared by a document
288+ (including the external subset if the parser uses it and can provide
289+ the information) is available from a \class {DocumentType} object. The
290+ \class {DocumentType} for a document is available from the
291+ \class {Document} object's \member {doctype} attribute.
292+
293+ \class {DocumentType} is a specialization of \class {Node}, and adds the
294+ following attributes:
295+
296+ \begin {memberdesc }[DocumentType]{publicId}
297+ The public identifier for the external subset of the document type
298+ definition. This will be a string or \code {None}.
299+ \end {memberdesc }
300+
301+ \begin {memberdesc }[DocumentType]{systemId}
302+ The system identifier for the external subset of the document type
303+ definition. This will be a URI as a string, or \code {None}.
304+ \end {memberdesc }
305+
306+ \begin {memberdesc }[DocumentType]{internalSubset}
307+ A string giving the complete internal subset from the document.
308+ \end {memberdesc }
309+
310+ \begin {memberdesc }[DocumentType]{name}
311+ The name of the root element as given in the \code {DOCTYPE}
312+ declaration, if present. If the was no \code {DOCTYPE} declaration,
313+ this will be \code {None}.
314+ \end {memberdesc }
315+
316+ \begin {memberdesc }[DocumentType]{entities}
317+ This is a \class {NamedNodeMap} giving the definitions of external
318+ entities. For entity names defined more than once, only the first
319+ definition is provided (others are ignored as required by the XML
320+ recommendation). This may be \code {None} if the information is not
321+ provided by the parser, or if no entities are defined.
322+ \end {memberdesc }
323+
324+ \begin {memberdesc }[DocumentType]{notations}
325+ This is a \class {NamedNodeMap} giving the definitions of notations.
326+ For notation names defined more than once, only the first definition
327+ is provided (others are ignored as required by the XML
328+ recommendation). This may be \code {None} if the information is not
329+ provided by the parser, or if no notations are defined.
330+ \end {memberdesc }
331+
223332
224333\subsubsection {Document Objects \label {dom-document-objects } }
225334
@@ -232,50 +341,51 @@ \subsubsection{Document Objects \label{dom-document-objects}}
232341\end {memberdesc }
233342
234343\begin {methoddesc }[Document]{createElement}{tagName}
235- Create a new element. The element is not inserted into the document
236- when it is created. You need to explicitly insert it with one of the
237- other methods such as \method {insertBefore()} or
344+ Create and return a new element node . The element is not inserted
345+ into the document when it is created. You need to explicitly insert
346+ it with one of the other methods such as \method {insertBefore()} or
238347\method {appendChild()}.
239348\end {methoddesc }
240349
241350\begin {methoddesc }[Document]{createElementNS}{namespaceURI, tagName}
242- Create a new element with a namespace. The \var {tagName} may have a
243- prefix. The element is not inserted into the document when it is
244- created. You need to explicitly insert it with one of the other
245- methods such as \method {insertBefore()} or \method {appendChild()}.
351+ Create and return a new element with a namespace. The
352+ \var {tagName} may have a prefix. The element is not inserted into the
353+ document when it is created. You need to explicitly insert it with
354+ one of the other methods such as \method {insertBefore()} or
355+ \method {appendChild()}.
246356\end {methoddesc }
247357
248358\begin {methoddesc }[Document]{createTextNode}{data}
249- Create a text node containing the data passed as a parameter. As with
250- the other creation methods, this one does not insert the node into the
251- tree.
359+ Create and return a text node containing the data passed as a
360+ parameter. As with the other creation methods, this one does not
361+ insert the node into the tree.
252362\end {methoddesc }
253363
254364\begin {methoddesc }[Document]{createComment}{data}
255- Create a comment node containing the data passed as a parameter. As
256- with the other creation methods, this one does not insert the node
257- into the tree.
365+ Create and return a comment node containing the data passed as a
366+ parameter. As with the other creation methods, this one does not
367+ insert the node into the tree.
258368\end {methoddesc }
259369
260370\begin {methoddesc }[Document]{createProcessingInstruction}{target, data}
261- Create a processing instruction node containing the \var {target} and
262- \var {data} passed as parameters. As with the other creation methods,
263- this one does not insert the node into the tree.
371+ Create and return a processing instruction node containing the
372+ \var {target} and \var { data} passed as parameters. As with the other
373+ creation methods, this one does not insert the node into the tree.
264374\end {methoddesc }
265375
266376\begin {methoddesc }[Document]{createAttribute}{name}
267- Create an attribute node. This method does not associate the
268- attribute node with any particular element. You must use
377+ Create and return an attribute node. This method does not associate
378+ the attribute node with any particular element. You must use
269379\method {setAttributeNode()} on the appropriate \class {Element} object
270380to use the newly created attribute instance.
271381\end {methoddesc }
272382
273383\begin {methoddesc }[Document]{createAttributeNS}{namespaceURI, qualifiedName}
274- Create an attribute node with a namespace. The \var {tagName} may have
275- a prefix. This method does not associate the attribute node with any
276- particular element. You must use \method {setAttributeNode()} on the
277- appropriate \class {Element} object to use the newly created attribute
278- instance.
384+ Create and return an attribute node with a namespace. The
385+ \var {tagName} may have a prefix. This method does not associate the
386+ attribute node with any particular element. You must use
387+ \method {setAttributeNode()} on the appropriate \class {Element} object
388+ to use the newly created attribute instance.
279389\end {methoddesc }
280390
281391\begin {methoddesc }[Document]{getElementsByTagName}{tagName}
@@ -297,27 +407,27 @@ \subsubsection{Element Objects \label{dom-element-objects}}
297407
298408\begin {memberdesc }[Element]{tagName}
299409The element type name. In a namespace-using document it may have
300- colons in it.
410+ colons in it. The value is a string.
301411\end {memberdesc }
302412
303413\begin {memberdesc }[Element]{localName}
304414The part of the \member {tagName} following the colon if there is one,
305- else the entire \member {tagName}.
415+ else the entire \member {tagName}. The value is a string.
306416\end {memberdesc }
307417
308418\begin {memberdesc }[Element]{prefix}
309419The part of the \member {tagName} preceding the colon if there is one,
310- else the empty string.
311- \end {memberdesc }
312-
313- \begin {memberdesc }[Element]{namespaceURI}
314- The namespace associated with the tagName.
420+ else the empty string. The value is a string, or \code {None}
315421\end {memberdesc }
316422
317423\begin {methoddesc }[Element]{getAttribute}{attname}
318424Return an attribute value as a string.
319425\end {methoddesc }
320426
427+ \begin {methoddesc }[Element]{getAttributeNode}{attrname}
428+ Return the \class {Attr} node for the attribute named by \var {attrname}
429+ \end {methoddesc }
430+
321431\begin {methoddesc }[Element]{setAttribute}{attname, value}
322432Set an attribute value from a string.
323433\end {methoddesc }
@@ -439,9 +549,27 @@ \subsection{Conformance \label{dom-conformance}}
439549between the Python DOM API, the W3C DOM recommendations, and the OMG
440550IDL mapping for Python.
441551
552+
442553\subsubsection {Type Mapping \label {dom-type-mapping } }
443554
444- XXX Explain what a \class {DOMString} maps to...
555+ The primitive IDL types used in the DOM specification are mapped to
556+ Python types according to the following table.
557+
558+ \begin {tableii }{l|l}{code}{IDL Type}{Python Type}
559+ \lineii {boolean}{\code {IntegerType} (with a value of \code {0} or \code {1})}
560+ \lineii {int}{\code {IntegerType}}
561+ \lineii {long int}{\code {IntegerType}}
562+ \lineii {unsigned int}{\code {IntegerType}}
563+ \end {tableii }
564+
565+ Additionally, the \class {DOMString} defined in the recommendation is
566+ mapped to a Python string or Unicode string. Applications should
567+ be able to handle Unicode whenever a string is returned from the DOM.
568+
569+ The IDL \keyword {null} value is mapped to \code {None}, which may be
570+ accepted or provided by the implementation whenever \keyword {null} is
571+ allowed by the API.
572+
445573
446574\subsubsection {Accessor Methods \label {dom-accessor-methods } }
447575
@@ -476,4 +604,5 @@ \subsubsection{Accessor Methods \label{dom-accessor-methods}}
476604Additionally, the accessor functions are not required. If provided,
477605they should take the form defined by the Python IDL mapping, but
478606these methods are considered unnecessary since the attributes are
479- accessible directly from Python.
607+ accessible directly from Python. `` Set'' accessors should never be
608+ provided for \keyword {readonly} attributes.
0 commit comments