Commit | Line | Data |
---|---|---|
920dae64 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="module-xml.dom.minidom.html" /> | |
13 | <link rel="prev" href="module-xml.parsers.expat.html" /> | |
14 | <link rel="parent" href="markup.html" /> | |
15 | <link rel="next" href="node651.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>13.6 xml.dom -- The Document Object Model API</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.5.5 Expat error constants" | |
25 | href="expat-errors.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. Structured Markup Processing" | |
28 | href="markup.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.1 Module Contents" | |
31 | href="node651.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="expat-errors.html">13.5.5 Expat error constants</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="markup.html">13. Structured Markup Processing</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node651.html">13.6.1 Module Contents</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0015600000000000000000"> | |
56 | 13.6 <tt class="module">xml.dom</tt> -- | |
57 | The Document Object Model API</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-xml.dom"></A> | |
62 | ||
63 | <P> | |
64 | ||
65 | <span class="versionnote">New in version 2.0.</span> | |
66 | ||
67 | <P> | |
68 | The Document Object Model, or ``DOM,'' is a cross-language API from | |
69 | the World Wide Web Consortium (W3C) for accessing and modifying XML | |
70 | documents. A DOM implementation presents an XML document as a tree | |
71 | structure, or allows client code to build such a structure from | |
72 | scratch. It then gives access to the structure through a set of | |
73 | objects which provided well-known interfaces. | |
74 | ||
75 | <P> | |
76 | The DOM is extremely useful for random-access applications. SAX only | |
77 | allows you a view of one bit of the document at a time. If you are | |
78 | looking at one SAX element, you have no access to another. If you are | |
79 | looking at a text node, you have no access to a containing element. | |
80 | When you write a SAX application, you need to keep track of your | |
81 | program's position in the document somewhere in your own code. SAX | |
82 | does not do it for you. Also, if you need to look ahead in the XML | |
83 | document, you are just out of luck. | |
84 | ||
85 | <P> | |
86 | Some applications are simply impossible in an event driven model with | |
87 | no access to a tree. Of course you could build some sort of tree | |
88 | yourself in SAX events, but the DOM allows you to avoid writing that | |
89 | code. The DOM is a standard tree representation for XML data. | |
90 | ||
91 | <P> | |
92 | The Document Object Model is being defined by the W3C in stages, or | |
93 | ``levels'' in their terminology. The Python mapping of the API is | |
94 | substantially based on the DOM Level 2 recommendation. The mapping of | |
95 | the Level 3 specification, currently only available in draft form, is | |
96 | being developed by the <a class="ulink" href="http://www.python.org/sigs/xml-sig/" | |
97 | >Python XML Special Interest | |
98 | Group</a> as part of the | |
99 | <a class="ulink" href="http://pyxml.sourceforge.net/" | |
100 | >PyXML package</a>. Refer to the | |
101 | documentation bundled with that package for information on the current | |
102 | state of DOM Level 3 support. | |
103 | ||
104 | <P> | |
105 | DOM applications typically start by parsing some XML into a DOM. How | |
106 | this is accomplished is not covered at all by DOM Level 1, and Level 2 | |
107 | provides only limited improvements: There is a | |
108 | <tt class="class">DOMImplementation</tt> object class which provides access to | |
109 | <tt class="class">Document</tt> creation methods, but no way to access an XML | |
110 | reader/parser/Document builder in an implementation-independent way. | |
111 | There is also no well-defined way to access these methods without an | |
112 | existing <tt class="class">Document</tt> object. In Python, each DOM implementation | |
113 | will provide a function <tt class="function">getDOMImplementation()</tt>. DOM Level 3 | |
114 | adds a Load/Store specification, which defines an interface to the | |
115 | reader, but this is not yet available in the Python standard library. | |
116 | ||
117 | <P> | |
118 | Once you have a DOM document object, you can access the parts of your | |
119 | XML document through its properties and methods. These properties are | |
120 | defined in the DOM specification; this portion of the reference manual | |
121 | describes the interpretation of the specification in Python. | |
122 | ||
123 | <P> | |
124 | The specification provided by the W3C defines the DOM API for Java, | |
125 | ECMAScript, and OMG IDL. The Python mapping defined here is based in | |
126 | large part on the IDL version of the specification, but strict | |
127 | compliance is not required (though implementations are free to support | |
128 | the strict mapping from IDL). See section <A href="dom-conformance.html#dom-conformance">13.6.3</A>, | |
129 | ``Conformance,'' for a detailed discussion of mapping requirements. | |
130 | ||
131 | <P> | |
132 | <div class="seealso"> | |
133 | <p class="heading">See Also:</p> | |
134 | ||
135 | <dl compact="compact" class="seetitle"> | |
136 | <dt><em class="citetitle"><a href="http://www.w3.org/TR/DOM-Level-2-Core/" | |
137 | >Document Object | |
138 | Model (DOM) Level 2 Specification</a></em></dt> | |
139 | <dd>The W3C recommendation upon which the Python DOM API is | |
140 | based.</dd> | |
141 | </dl> | |
142 | <dl compact="compact" class="seetitle"> | |
143 | <dt><em class="citetitle"><a href="http://www.w3.org/TR/REC-DOM-Level-1/" | |
144 | >Document Object | |
145 | Model (DOM) Level 1 Specification</a></em></dt> | |
146 | <dd>The W3C recommendation for the | |
147 | DOM supported by <tt class="module">xml.dom.minidom</tt>.</dd> | |
148 | </dl> | |
149 | <dl compact="compact" class="seetitle"> | |
150 | <dt><em class="citetitle"><a href="http://pyxml.sourceforge.net" | |
151 | >PyXML</a></em></dt> | |
152 | <dd>Users that require a | |
153 | full-featured implementation of DOM should use the PyXML | |
154 | package.</dd> | |
155 | </dl> | |
156 | <dl compact="compact" class="seetitle"> | |
157 | <dt><em class="citetitle"><a href="http://www.omg.org/docs/formal/02-11-05.pdf" | |
158 | >Python | |
159 | Language Mapping Specification</a></em></dt> | |
160 | <dd>This specifies the mapping from OMG IDL to Python.</dd> | |
161 | </dl> | |
162 | </div> | |
163 | ||
164 | <P> | |
165 | ||
166 | <p><br /></p><hr class='online-navigation' /> | |
167 | <div class='online-navigation'> | |
168 | <!--Table of Child-Links--> | |
169 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
170 | ||
171 | <UL CLASS="ChildLinks"> | |
172 | <LI><A href="node651.html">13.6.1 Module Contents</a> | |
173 | <LI><A href="node652.html">13.6.2 Objects in the DOM</a> | |
174 | <UL> | |
175 | <LI><A href="dom-implementation-objects.html">13.6.2.1 DOMImplementation Objects</a> | |
176 | <LI><A href="dom-node-objects.html">13.6.2.2 Node Objects</a> | |
177 | <LI><A href="dom-nodelist-objects.html">13.6.2.3 NodeList Objects</a> | |
178 | <LI><A href="dom-documenttype-objects.html">13.6.2.4 DocumentType Objects</a> | |
179 | <LI><A href="dom-document-objects.html">13.6.2.5 Document Objects</a> | |
180 | <LI><A href="dom-element-objects.html">13.6.2.6 Element Objects</a> | |
181 | <LI><A href="dom-attr-objects.html">13.6.2.7 Attr Objects</a> | |
182 | <LI><A href="dom-attributelist-objects.html">13.6.2.8 NamedNodeMap Objects</a> | |
183 | <LI><A href="dom-comment-objects.html">13.6.2.9 Comment Objects</a> | |
184 | <LI><A href="dom-text-objects.html">13.6.2.10 Text and CDATASection Objects</a> | |
185 | <LI><A href="dom-pi-objects.html">13.6.2.11 ProcessingInstruction Objects</a> | |
186 | <LI><A href="dom-exceptions.html">13.6.2.12 Exceptions</a> | |
187 | </ul> | |
188 | <LI><A href="dom-conformance.html">13.6.3 Conformance</a> | |
189 | <UL> | |
190 | <LI><A href="dom-type-mapping.html">13.6.3.1 Type Mapping</a> | |
191 | <LI><A href="dom-accessor-methods.html">13.6.3.2 Accessor Methods</a> | |
192 | </ul></ul> | |
193 | <!--End of Table of Child-Links--> | |
194 | </div> | |
195 | ||
196 | <DIV CLASS="navigation"> | |
197 | <div class='online-navigation'> | |
198 | <p></p><hr /> | |
199 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
200 | <tr> | |
201 | <td class='online-navigation'><a rel="prev" title="13.5.5 Expat error constants" | |
202 | href="expat-errors.html"><img src='../icons/previous.png' | |
203 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
204 | <td class='online-navigation'><a rel="parent" title="13. Structured Markup Processing" | |
205 | href="markup.html"><img src='../icons/up.png' | |
206 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
207 | <td class='online-navigation'><a rel="next" title="13.6.1 Module Contents" | |
208 | href="node651.html"><img src='../icons/next.png' | |
209 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
210 | <td align="center" width="100%">Python Library Reference</td> | |
211 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
212 | href="contents.html"><img src='../icons/contents.png' | |
213 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
214 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
215 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
216 | <td class='online-navigation'><a rel="index" title="Index" | |
217 | href="genindex.html"><img src='../icons/index.png' | |
218 | border='0' height='32' alt='Index' width='32' /></A></td> | |
219 | </tr></table> | |
220 | <div class='online-navigation'> | |
221 | <b class="navlabel">Previous:</b> | |
222 | <a class="sectref" rel="prev" href="expat-errors.html">13.5.5 Expat error constants</A> | |
223 | <b class="navlabel">Up:</b> | |
224 | <a class="sectref" rel="parent" href="markup.html">13. Structured Markup Processing</A> | |
225 | <b class="navlabel">Next:</b> | |
226 | <a class="sectref" rel="next" href="node651.html">13.6.1 Module Contents</A> | |
227 | </div> | |
228 | </div> | |
229 | <hr /> | |
230 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
231 | </DIV> | |
232 | <!--End of Navigation Panel--> | |
233 | <ADDRESS> | |
234 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
235 | </ADDRESS> | |
236 | </BODY> | |
237 | </HTML> |