| 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-example.html" /> |
| 13 | <link rel="prev" href="module-xml.dom.minidom.html" /> |
| 14 | <link rel="parent" href="module-xml.dom.minidom.html" /> |
| 15 | <link rel="next" href="dom-example.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>13.7.1 DOM 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.7 xml.dom.minidom " |
| 25 | href="module-xml.dom.minidom.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.7 xml.dom.minidom " |
| 28 | href="module-xml.dom.minidom.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.7.2 DOM Example" |
| 31 | href="dom-example.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="module-xml.dom.minidom.html">13.7 xml.dom.minidom </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-xml.dom.minidom.html">13.7 xml.dom.minidom </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="dom-example.html">13.7.2 DOM Example</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION0015710000000000000000"></A><A NAME="dom-objects"></A> |
| 56 | <BR> |
| 57 | 13.7.1 DOM Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | The definition of the DOM API for Python is given as part of the |
| 62 | <tt class="module"><a href="module-xml.dom.html">xml.dom</a></tt> module documentation. This section lists the |
| 63 | differences between the API and <tt class="module"><a href="module-xml.dom.minidom.html">xml.dom.minidom</a></tt>. |
| 64 | |
| 65 | <P> |
| 66 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 67 | <td><nobr><b><tt id='l2h-4447' xml:id='l2h-4447' class="method">unlink</tt></b>(</nobr></td> |
| 68 | <td><var></var>)</td></tr></table></dt> |
| 69 | <dd> |
| 70 | Break internal references within the DOM so that it will be garbage |
| 71 | collected on versions of Python without cyclic GC. Even when cyclic |
| 72 | GC is available, using this can make large amounts of memory available |
| 73 | sooner, so calling this on DOM objects as soon as they are no longer |
| 74 | needed is good practice. This only needs to be called on the |
| 75 | <tt class="class">Document</tt> object, but may be called on child nodes to discard |
| 76 | children of that node. |
| 77 | </dl> |
| 78 | |
| 79 | <P> |
| 80 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 81 | <td><nobr><b><tt id='l2h-4448' xml:id='l2h-4448' class="method">writexml</tt></b>(</nobr></td> |
| 82 | <td><var>writer</var><big>[</big><var>,indent=""</var><big>[</big><var>,addindent=""</var><big>[</big><var>,newl=""</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 83 | <dd> |
| 84 | Write XML to the writer object. The writer should have a |
| 85 | <tt class="method">write()</tt> method which matches that of the file object |
| 86 | interface. The <var>indent</var> parameter is the indentation of the current |
| 87 | node. The <var>addindent</var> parameter is the incremental indentation to use |
| 88 | for subnodes of the current one. The <var>newl</var> parameter specifies the |
| 89 | string to use to terminate newlines. |
| 90 | |
| 91 | <P> |
| 92 | |
| 93 | <span class="versionnote">Changed in version 2.1: |
| 94 | The optional keyword parameters |
| 95 | <var>indent</var>, <var>addindent</var>, and <var>newl</var> were added to support pretty |
| 96 | output.</span> |
| 97 | |
| 98 | <P> |
| 99 | |
| 100 | <span class="versionnote">Changed in version 2.3: |
| 101 | For the <tt class="class">Document</tt> node, an additional keyword |
| 102 | argument <var>encoding</var> can be used to specify the encoding field of the XML |
| 103 | header.</span> |
| 104 | |
| 105 | </dl> |
| 106 | |
| 107 | <P> |
| 108 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 109 | <td><nobr><b><tt id='l2h-4449' xml:id='l2h-4449' class="method">toxml</tt></b>(</nobr></td> |
| 110 | <td><var></var><big>[</big><var>encoding</var><big>]</big><var></var>)</td></tr></table></dt> |
| 111 | <dd> |
| 112 | Return the XML that the DOM represents as a string. |
| 113 | |
| 114 | <P> |
| 115 | With no argument, the XML header does not specify an encoding, and the |
| 116 | result is Unicode string if the default encoding cannot represent all |
| 117 | characters in the document. Encoding this string in an encoding other |
| 118 | than UTF-8 is likely incorrect, since UTF-8 is the default encoding of |
| 119 | XML. |
| 120 | |
| 121 | <P> |
| 122 | With an explicit <var>encoding</var> argument, the result is a byte string |
| 123 | in the specified encoding. It is recommended that this argument is |
| 124 | always specified. To avoid UnicodeError exceptions in case of |
| 125 | unrepresentable text data, the encoding argument should be specified |
| 126 | as "utf-8". |
| 127 | |
| 128 | <P> |
| 129 | |
| 130 | <span class="versionnote">Changed in version 2.3: |
| 131 | the <var>encoding</var> argument was introduced.</span> |
| 132 | |
| 133 | </dl> |
| 134 | |
| 135 | <P> |
| 136 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 137 | <td><nobr><b><tt id='l2h-4450' xml:id='l2h-4450' class="method">toprettyxml</tt></b>(</nobr></td> |
| 138 | <td><var></var><big>[</big><var>indent</var><big>[</big><var>, newl</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 139 | <dd> |
| 140 | Return a pretty-printed version of the document. <var>indent</var> specifies |
| 141 | the indentation string and defaults to a tabulator; <var>newl</var> specifies |
| 142 | the string emitted at the end of each line and defaults to |
| 143 | <BR> |
| 144 | n. |
| 145 | |
| 146 | <P> |
| 147 | |
| 148 | <span class="versionnote">New in version 2.1.</span> |
| 149 | |
| 150 | <span class="versionnote">Changed in version 2.3: |
| 151 | the encoding argument; see <tt class="method">toxml()</tt>.</span> |
| 152 | |
| 153 | </dl> |
| 154 | |
| 155 | <P> |
| 156 | The following standard DOM methods have special considerations with |
| 157 | <tt class="module"><a href="module-xml.dom.minidom.html">xml.dom.minidom</a></tt>: |
| 158 | |
| 159 | <P> |
| 160 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 161 | <td><nobr><b><tt id='l2h-4451' xml:id='l2h-4451' class="method">cloneNode</tt></b>(</nobr></td> |
| 162 | <td><var>deep</var>)</td></tr></table></dt> |
| 163 | <dd> |
| 164 | Although this method was present in the version of |
| 165 | <tt class="module"><a href="module-xml.dom.minidom.html">xml.dom.minidom</a></tt> packaged with Python 2.0, it was seriously |
| 166 | broken. This has been corrected for subsequent releases. |
| 167 | </dl> |
| 168 | |
| 169 | <P> |
| 170 | |
| 171 | <DIV CLASS="navigation"> |
| 172 | <div class='online-navigation'> |
| 173 | <p></p><hr /> |
| 174 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 175 | <tr> |
| 176 | <td class='online-navigation'><a rel="prev" title="13.7 xml.dom.minidom " |
| 177 | href="module-xml.dom.minidom.html"><img src='../icons/previous.png' |
| 178 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 179 | <td class='online-navigation'><a rel="parent" title="13.7 xml.dom.minidom " |
| 180 | href="module-xml.dom.minidom.html"><img src='../icons/up.png' |
| 181 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 182 | <td class='online-navigation'><a rel="next" title="13.7.2 DOM Example" |
| 183 | href="dom-example.html"><img src='../icons/next.png' |
| 184 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 185 | <td align="center" width="100%">Python Library Reference</td> |
| 186 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 187 | href="contents.html"><img src='../icons/contents.png' |
| 188 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 189 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 190 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 191 | <td class='online-navigation'><a rel="index" title="Index" |
| 192 | href="genindex.html"><img src='../icons/index.png' |
| 193 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 194 | </tr></table> |
| 195 | <div class='online-navigation'> |
| 196 | <b class="navlabel">Previous:</b> |
| 197 | <a class="sectref" rel="prev" href="module-xml.dom.minidom.html">13.7 xml.dom.minidom </A> |
| 198 | <b class="navlabel">Up:</b> |
| 199 | <a class="sectref" rel="parent" href="module-xml.dom.minidom.html">13.7 xml.dom.minidom </A> |
| 200 | <b class="navlabel">Next:</b> |
| 201 | <a class="sectref" rel="next" href="dom-example.html">13.7.2 DOM Example</A> |
| 202 | </div> |
| 203 | </div> |
| 204 | <hr /> |
| 205 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 206 | </DIV> |
| 207 | <!--End of Navigation Panel--> |
| 208 | <ADDRESS> |
| 209 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 210 | </ADDRESS> |
| 211 | </BODY> |
| 212 | </HTML> |