/
usr
/
share
/
doc
/
python2-docs
/
html
/
_sources
/
library
/
/usr/share/doc/python2-docs/html/_sources/library
mkdir
upload
Name
Size
Mode
Actions
2to3.rst.txt
14647
0644
edit
dl
rm
abc.rst.txt
7219
0644
edit
dl
rm
aepack.rst.txt
4257
0644
edit
dl
rm
aetools.rst.txt
3532
0644
edit
dl
rm
aetypes.rst.txt
4257
0644
edit
dl
rm
aifc.rst.txt
7086
0644
edit
dl
rm
al.rst.txt
5309
0644
edit
dl
rm
allos.rst.txt
695
0644
edit
dl
rm
anydbm.rst.txt
4111
0644
edit
dl
rm
archiving.rst.txt
424
0644
edit
dl
rm
argparse.rst.txt
74685
0644
edit
dl
rm
array.rst.txt
10524
0644
edit
dl
rm
ast.rst.txt
10111
0644
edit
dl
rm
asynchat.rst.txt
9206
0644
edit
dl
rm
asyncore.rst.txt
12937
0644
edit
dl
rm
atexit.rst.txt
3910
0644
edit
dl
rm
audioop.rst.txt
10395
0644
edit
dl
rm
autogil.rst.txt
1015
0644
edit
dl
rm
base64.rst.txt
6252
0644
edit
dl
rm
basehttpserver.rst.txt
10404
0644
edit
dl
rm
bastion.rst.txt
2611
0644
edit
dl
rm
bdb.rst.txt
12456
0644
edit
dl
rm
binascii.rst.txt
6508
0644
edit
dl
rm
binhex.rst.txt
1910
0644
edit
dl
rm
bisect.rst.txt
5415
0644
edit
dl
rm
bsddb.rst.txt
7575
0644
edit
dl
rm
bz2.rst.txt
8064
0644
edit
dl
rm
calendar.rst.txt
11282
0644
edit
dl
rm
carbon.rst.txt
15956
0644
edit
dl
rm
cd.rst.txt
11974
0644
edit
dl
rm
cgi.rst.txt
22853
0644
edit
dl
rm
cgihttpserver.rst.txt
2788
0644
edit
dl
rm
cgitb.rst.txt
2874
0644
edit
dl
rm
chunk.rst.txt
4955
0644
edit
dl
rm
cmath.rst.txt
7647
0644
edit
dl
rm
cmd.rst.txt
8565
0644
edit
dl
rm
code.rst.txt
7115
0644
edit
dl
rm
codecs.rst.txt
66966
0644
edit
dl
rm
codeop.rst.txt
3774
0644
edit
dl
rm
collections.rst.txt
41448
0644
edit
dl
rm
colorpicker.rst.txt
913
0644
edit
dl
rm
colorsys.rst.txt
1819
0644
edit
dl
rm
commands.rst.txt
2595
0644
edit
dl
rm
compileall.rst.txt
4678
0644
edit
dl
rm
compiler.rst.txt
37464
0644
edit
dl
rm
configparser.rst.txt
19607
0644
edit
dl
rm
constants.rst.txt
2328
0644
edit
dl
rm
contextlib.rst.txt
6012
0644
edit
dl
rm
cookie.rst.txt
9543
0644
edit
dl
rm
cookielib.rst.txt
27875
0644
edit
dl
rm
copy.rst.txt
3351
0644
edit
dl
rm
copy_reg.rst.txt
2329
0644
edit
dl
rm
crypt.rst.txt
2292
0644
edit
dl
rm
crypto.rst.txt
355
0644
edit
dl
rm
csv.rst.txt
22757
0644
edit
dl
rm
ctypes.rst.txt
90513
0644
edit
dl
rm
curses.ascii.rst.txt
9046
0644
edit
dl
rm
curses.panel.rst.txt
2740
0644
edit
dl
rm
curses.rst.txt
74877
0644
edit
dl
rm
custominterp.rst.txt
570
0644
edit
dl
rm
datatypes.rst.txt
864
0644
edit
dl
rm
datetime.rst.txt
74679
0644
edit
dl
rm
dbhash.rst.txt
3865
0644
edit
dl
rm
dbm.rst.txt
3117
0644
edit
dl
rm
debug.rst.txt
446
0644
edit
dl
rm
decimal.rst.txt
70926
0644
edit
dl
rm
development.rst.txt
640
0644
edit
dl
rm
difflib.rst.txt
30716
0644
edit
dl
rm
dircache.rst.txt
1813
0644
edit
dl
rm
dis.rst.txt
23248
0644
edit
dl
rm
distribution.rst.txt
426
0644
edit
dl
rm
distutils.rst.txt
1958
0644
edit
dl
rm
dl.rst.txt
3392
0644
edit
dl
rm
doctest.rst.txt
73985
0644
edit
dl
rm
docxmlrpcserver.rst.txt
3802
0644
edit
dl
rm
dumbdbm.rst.txt
2841
0644
edit
dl
rm
dummy_thread.rst.txt
1058
0644
edit
dl
rm
dummy_threading.rst.txt
799
0644
edit
dl
rm
easydialogs.rst.txt
10346
0644
edit
dl
rm
email-examples.rst.txt
1271
0644
edit
dl
rm
email.charset.rst.txt
9654
0644
edit
dl
rm
email.encoders.rst.txt
2376
0644
edit
dl
rm
email.errors.rst.txt
4006
0644
edit
dl
rm
email.generator.rst.txt
6132
0644
edit
dl
rm
email.header.rst.txt
7531
0644
edit
dl
rm
email.iterators.rst.txt
2421
0644
edit
dl
rm
email.message.rst.txt
25217
0644
edit
dl
rm
email.mime.rst.txt
9917
0644
edit
dl
rm
email.parser.rst.txt
10327
0644
edit
dl
rm
email.rst.txt
16111
0644
edit
dl
rm
email.utils.rst.txt
6475
0644
edit
dl
rm
ensurepip.rst.txt
5022
0644
edit
dl
rm
errno.rst.txt
6708
0644
edit
dl
rm
exceptions.rst.txt
18343
0644
edit
dl
rm
fcntl.rst.txt
7361
0644
edit
dl
rm
filecmp.rst.txt
5348
0644
edit
dl
rm
fileformats.rst.txt
302
0644
edit
dl
rm
fileinput.rst.txt
7417
0644
edit
dl
rm
filesys.rst.txt
806
0644
edit
dl
rm
fl.rst.txt
17646
0644
edit
dl
rm
fm.rst.txt
2699
0644
edit
dl
rm
fnmatch.rst.txt
3104
0644
edit
dl
rm
formatter.rst.txt
13245
0644
edit
dl
rm
fpectl.rst.txt
4171
0644
edit
dl
rm
fpformat.rst.txt
1747
0644
edit
dl
rm
fractions.rst.txt
5297
0644
edit
dl
rm
framework.rst.txt
11444
0644
edit
dl
rm
frameworks.rst.txt
378
0644
edit
dl
rm
ftplib.rst.txt
15720
0644
edit
dl
rm
functions.rst.txt
75554
0644
edit
dl
rm
functools.rst.txt
7448
0644
edit
dl
rm
future_builtins.rst.txt
2010
0644
edit
dl
rm
gc.rst.txt
9014
0644
edit
dl
rm
gdbm.rst.txt
4882
0644
edit
dl
rm
gensuitemodule.rst.txt
3113
0644
edit
dl
rm
getopt.rst.txt
6670
0644
edit
dl
rm
getpass.rst.txt
1876
0644
edit
dl
rm
gettext.rst.txt
29040
0644
edit
dl
rm
gl.rst.txt
6009
0644
edit
dl
rm
glob.rst.txt
2414
0644
edit
dl
rm
grp.rst.txt
2256
0644
edit
dl
rm
gzip.rst.txt
4828
0644
edit
dl
rm
hashlib.rst.txt
7379
0644
edit
dl
rm
heapq.rst.txt
13185
0644
edit
dl
rm
hmac.rst.txt
3073
0644
edit
dl
rm
hotshot.rst.txt
4289
0644
edit
dl
rm
htmllib.rst.txt
7379
0644
edit
dl
rm
htmlparser.rst.txt
11640
0644
edit
dl
rm
httplib.rst.txt
37454
0644
edit
dl
rm
i18n.rst.txt
409
0644
edit
dl
rm
ic.rst.txt
5005
0644
edit
dl
rm
idle.rst.txt
22182
0644
edit
dl
rm
imageop.rst.txt
4001
0644
edit
dl
rm
imaplib.rst.txt
17221
0644
edit
dl
rm
imgfile.rst.txt
2765
0644
edit
dl
rm
imghdr.rst.txt
2635
0644
edit
dl
rm
imp.rst.txt
12593
0644
edit
dl
rm
importlib.rst.txt
1126
0644
edit
dl
rm
imputil.rst.txt
7023
0644
edit
dl
rm
index.rst.txt
2287
0644
edit
dl
rm
inspect.rst.txt
28151
0644
edit
dl
rm
internet.rst.txt
950
0644
edit
dl
rm
intro.rst.txt
2803
0644
edit
dl
rm
io.rst.txt
39015
0644
edit
dl
rm
ipc.rst.txt
630
0644
edit
dl
rm
itertools.rst.txt
36324
0644
edit
dl
rm
jpeg.rst.txt
3858
0644
edit
dl
rm
json.rst.txt
25545
0644
edit
dl
rm
keyword.rst.txt
617
0644
edit
dl
rm
language.rst.txt
523
0644
edit
dl
rm
linecache.rst.txt
1887
0644
edit
dl
rm
locale.rst.txt
24975
0644
edit
dl
rm
logging.config.rst.txt
31560
0644
edit
dl
rm
logging.handlers.rst.txt
28153
0644
edit
dl
rm
logging.rst.txt
46882
0644
edit
dl
rm
mac.rst.txt
791
0644
edit
dl
rm
macos.rst.txt
3824
0644
edit
dl
rm
macosa.rst.txt
3964
0644
edit
dl
rm
macostools.rst.txt
4017
0644
edit
dl
rm
macpath.rst.txt
650
0644
edit
dl
rm
mailbox.rst.txt
68129
0644
edit
dl
rm
mailcap.rst.txt
3675
0644
edit
dl
rm
markup.rst.txt
1249
0644
edit
dl
rm
marshal.rst.txt
5689
0644
edit
dl
rm
math.rst.txt
10920
0644
edit
dl
rm
md5.rst.txt
2815
0644
edit
dl
rm
mhlib.rst.txt
3966
0644
edit
dl
rm
mimetools.rst.txt
4504
0644
edit
dl
rm
mimetypes.rst.txt
9839
0644
edit
dl
rm
mimewriter.rst.txt
3360
0644
edit
dl
rm
mimify.rst.txt
3519
0644
edit
dl
rm
miniaeframe.rst.txt
2564
0644
edit
dl
rm
misc.rst.txt
248
0644
edit
dl
rm
mm.rst.txt
447
0644
edit
dl
rm
mmap.rst.txt
10481
0644
edit
dl
rm
modulefinder.rst.txt
3380
0644
edit
dl
rm
modules.rst.txt
382
0644
edit
dl
rm
msilib.rst.txt
19062
0644
edit
dl
rm
msvcrt.rst.txt
4346
0644
edit
dl
rm
multifile.rst.txt
6613
0644
edit
dl
rm
multiprocessing.rst.txt
92621
0644
edit
dl
rm
mutex.rst.txt
1939
0644
edit
dl
rm
netdata.rst.txt
432
0644
edit
dl
rm
netrc.rst.txt
3119
0644
edit
dl
rm
new.rst.txt
2653
0644
edit
dl
rm
nis.rst.txt
2108
0644
edit
dl
rm
nntplib.rst.txt
14531
0644
edit
dl
rm
numbers.rst.txt
8007
0644
edit
dl
rm
numeric.rst.txt
751
0644
edit
dl
rm
operator.rst.txt
22092
0644
edit
dl
rm
optparse.rst.txt
77101
0644
edit
dl
rm
os.path.rst.txt
13094
0644
edit
dl
rm
os.rst.txt
82580
0644
edit
dl
rm
ossaudiodev.rst.txt
17309
0644
edit
dl
rm
othergui.rst.txt
2721
0644
edit
dl
rm
parser.rst.txt
15385
0644
edit
dl
rm
pdb.rst.txt
16043
0644
edit
dl
rm
persistence.rst.txt
826
0644
edit
dl
rm
pickle.rst.txt
37262
0644
edit
dl
rm
pickletools.rst.txt
1997
0644
edit
dl
rm
pipes.rst.txt
3786
0644
edit
dl
rm
pkgutil.rst.txt
7714
0644
edit
dl
rm
platform.rst.txt
9554
0644
edit
dl
rm
plistlib.rst.txt
4134
0644
edit
dl
rm
popen2.rst.txt
7022
0644
edit
dl
rm
poplib.rst.txt
6220
0644
edit
dl
rm
posix.rst.txt
3630
0644
edit
dl
rm
posixfile.rst.txt
7200
0644
edit
dl
rm
pprint.rst.txt
9071
0644
edit
dl
rm
profile.rst.txt
28666
0644
edit
dl
rm
pty.rst.txt
1762
0644
edit
dl
rm
pwd.rst.txt
2725
0644
edit
dl
rm
pyclbr.rst.txt
3296
0644
edit
dl
rm
pydoc.rst.txt
4083
0644
edit
dl
rm
pyexpat.rst.txt
28891
0644
edit
dl
rm
python.rst.txt
514
0644
edit
dl
rm
py_compile.rst.txt
2479
0644
edit
dl
rm
queue.rst.txt
7034
0644
edit
dl
rm
quopri.rst.txt
2670
0644
edit
dl
rm
random.rst.txt
13319
0644
edit
dl
rm
re.rst.txt
55102
0644
edit
dl
rm
readline.rst.txt
10513
0644
edit
dl
rm
repr.rst.txt
4718
0644
edit
dl
rm
resource.rst.txt
9595
0644
edit
dl
rm
restricted.rst.txt
3327
0644
edit
dl
rm
rexec.rst.txt
11742
0644
edit
dl
rm
rfc822.rst.txt
14037
0644
edit
dl
rm
rlcompleter.rst.txt
2494
0644
edit
dl
rm
robotparser.rst.txt
2190
0644
edit
dl
rm
runpy.rst.txt
6938
0644
edit
dl
rm
sched.rst.txt
4644
0644
edit
dl
rm
scrolledtext.rst.txt
1379
0644
edit
dl
rm
select.rst.txt
20705
0644
edit
dl
rm
sets.rst.txt
14973
0644
edit
dl
rm
sgi.rst.txt
322
0644
edit
dl
rm
sgmllib.rst.txt
10664
0644
edit
dl
rm
sha.rst.txt
2807
0644
edit
dl
rm
shelve.rst.txt
8319
0644
edit
dl
rm
shlex.rst.txt
11313
0644
edit
dl
rm
shutil.rst.txt
13491
0644
edit
dl
rm
signal.rst.txt
10719
0644
edit
dl
rm
simplehttpserver.rst.txt
4559
0644
edit
dl
rm
simplexmlrpcserver.rst.txt
10881
0644
edit
dl
rm
site.rst.txt
7880
0644
edit
dl
rm
smtpd.rst.txt
2464
0644
edit
dl
rm
smtplib.rst.txt
14906
0644
edit
dl
rm
sndhdr.rst.txt
1759
0644
edit
dl
rm
socket.rst.txt
40765
0644
edit
dl
rm
socketserver.rst.txt
22512
0644
edit
dl
rm
someos.rst.txt
599
0644
edit
dl
rm
spwd.rst.txt
2825
0644
edit
dl
rm
sqlite3.rst.txt
35448
0644
edit
dl
rm
ssl.rst.txt
76554
0644
edit
dl
rm
stat.rst.txt
7778
0644
edit
dl
rm
statvfs.rst.txt
1300
0644
edit
dl
rm
stdtypes.rst.txt
122668
0644
edit
dl
rm
string.rst.txt
44085
0644
edit
dl
rm
stringio.rst.txt
4166
0644
edit
dl
rm
stringprep.rst.txt
4238
0644
edit
dl
rm
strings.rst.txt
746
0644
edit
dl
rm
struct.rst.txt
17100
0644
edit
dl
rm
subprocess.rst.txt
33648
0644
edit
dl
rm
sun.rst.txt
249
0644
edit
dl
rm
sunau.rst.txt
7124
0644
edit
dl
rm
sunaudio.rst.txt
5849
0644
edit
dl
rm
symbol.rst.txt
975
0644
edit
dl
rm
symtable.rst.txt
5064
0644
edit
dl
rm
sys.rst.txt
47520
0644
edit
dl
rm
sysconfig.rst.txt
7639
0644
edit
dl
rm
syslog.rst.txt
3931
0644
edit
dl
rm
tabnanny.rst.txt
1999
0644
edit
dl
rm
tarfile.rst.txt
28214
0644
edit
dl
rm
telnetlib.rst.txt
7482
0644
edit
dl
rm
tempfile.rst.txt
10504
0644
edit
dl
rm
termios.rst.txt
3733
0644
edit
dl
rm
test.rst.txt
17659
0644
edit
dl
rm
textwrap.rst.txt
8552
0644
edit
dl
rm
thread.rst.txt
6588
0644
edit
dl
rm
threading.rst.txt
32468
0644
edit
dl
rm
time.rst.txt
26020
0644
edit
dl
rm
timeit.rst.txt
11598
0644
edit
dl
rm
tix.rst.txt
22693
0644
edit
dl
rm
tk.rst.txt
1612
0644
edit
dl
rm
tkinter.rst.txt
33456
0644
edit
dl
rm
token.rst.txt
2451
0644
edit
dl
rm
tokenize.rst.txt
5570
0644
edit
dl
rm
trace.rst.txt
6724
0644
edit
dl
rm
traceback.rst.txt
10711
0644
edit
dl
rm
ttk.rst.txt
57411
0644
edit
dl
rm
tty.rst.txt
1011
0644
edit
dl
rm
turtle.rst.txt
64097
0644
edit
dl
rm
types.rst.txt
6200
0644
edit
dl
rm
undoc.rst.txt
6550
0644
edit
dl
rm
unicodedata.rst.txt
5736
0644
edit
dl
rm
unittest.rst.txt
82952
0644
edit
dl
rm
unix.rst.txt
490
0644
edit
dl
rm
urllib.rst.txt
24960
0644
edit
dl
rm
urllib2.rst.txt
35211
0644
edit
dl
rm
urlparse.rst.txt
16071
0644
edit
dl
rm
user.rst.txt
2748
0644
edit
dl
rm
userdict.rst.txt
9290
0644
edit
dl
rm
uu.rst.txt
2369
0644
edit
dl
rm
uuid.rst.txt
8378
0644
edit
dl
rm
warnings.rst.txt
19815
0644
edit
dl
rm
wave.rst.txt
5047
0644
edit
dl
rm
weakref.rst.txt
12926
0644
edit
dl
rm
webbrowser.rst.txt
9863
0644
edit
dl
rm
whichdb.rst.txt
931
0644
edit
dl
rm
windows.rst.txt
273
0644
edit
dl
rm
winsound.rst.txt
5066
0644
edit
dl
rm
wsgiref.rst.txt
30567
0644
edit
dl
rm
xdrlib.rst.txt
8077
0644
edit
dl
rm
xml.dom.minidom.rst.txt
11208
0644
edit
dl
rm
xml.dom.pulldom.rst.txt
1571
0644
edit
dl
rm
xml.dom.rst.txt
40182
0644
edit
dl
rm
xml.etree.elementtree.rst.txt
35707
0644
edit
dl
rm
xml.rst.txt
6090
0644
edit
dl
rm
xml.sax.handler.rst.txt
15371
0644
edit
dl
rm
xml.sax.reader.rst.txt
12257
0644
edit
dl
rm
xml.sax.rst.txt
6460
0644
edit
dl
rm
xml.sax.utils.rst.txt
3560
0644
edit
dl
rm
xmlrpclib.rst.txt
22559
0644
edit
dl
rm
zipfile.rst.txt
18871
0644
edit
dl
rm
zipimport.rst.txt
5957
0644
edit
dl
rm
zlib.rst.txt
12766
0644
edit
dl
rm
_winreg.rst.txt
23305
0644
edit
dl
rm
__builtin__.rst.txt
1494
0644
edit
dl
rm
__future__.rst.txt
4952
0644
edit
dl
rm
__main__.rst.txt
535
0644
edit
dl
rm
Edit:
/usr/share/doc/python2-docs/html/_sources/library/xml.dom.rst.txt
(40182B)
:mod:`xml.dom` --- The Document Object Model API ================================================ .. module:: xml.dom :synopsis: Document Object Model API for Python. .. sectionauthor:: Paul Prescod <paul@prescod.net> .. sectionauthor:: Martin v. Löwis <martin@v.loewis.de> .. versionadded:: 2.0 The Document Object Model, or "DOM," is a cross-language API from the World Wide Web Consortium (W3C) for accessing and modifying XML documents. A DOM implementation presents an XML document as a tree structure, or allows client code to build such a structure from scratch. It then gives access to the structure through a set of objects which provided well-known interfaces. The DOM is extremely useful for random-access applications. SAX only allows you a view of one bit of the document at a time. If you are looking at one SAX element, you have no access to another. If you are looking at a text node, you have no access to a containing element. When you write a SAX application, you need to keep track of your program's position in the document somewhere in your own code. SAX does not do it for you. Also, if you need to look ahead in the XML document, you are just out of luck. Some applications are simply impossible in an event driven model with no access to a tree. Of course you could build some sort of tree yourself in SAX events, but the DOM allows you to avoid writing that code. The DOM is a standard tree representation for XML data. The Document Object Model is being defined by the W3C in stages, or "levels" in their terminology. The Python mapping of the API is substantially based on the DOM Level 2 recommendation. .. XXX PyXML is dead... .. The mapping of the Level 3 specification, currently only available in draft form, is being developed by the `Python XML Special Interest Group <https://www.python.org/sigs/xml-sig/>`_ as part of the `PyXML package <http://pyxml.sourceforge.net/>`_. Refer to the documentation bundled with that package for information on the current state of DOM Level 3 support. .. What if your needs are somewhere between SAX and the DOM? Perhaps you cannot afford to load the entire tree in memory but you find the SAX model somewhat cumbersome and low-level. There is also a module called xml.dom.pulldom that allows you to build trees of only the parts of a document that you need structured access to. It also has features that allow you to find your way around the DOM. See http://www.prescod.net/python/pulldom DOM applications typically start by parsing some XML into a DOM. How this is accomplished is not covered at all by DOM Level 1, and Level 2 provides only limited improvements: There is a :class:`DOMImplementation` object class which provides access to :class:`Document` creation methods, but no way to access an XML reader/parser/Document builder in an implementation-independent way. There is also no well-defined way to access these methods without an existing :class:`Document` object. In Python, each DOM implementation will provide a function :func:`getDOMImplementation`. DOM Level 3 adds a Load/Store specification, which defines an interface to the reader, but this is not yet available in the Python standard library. Once you have a DOM document object, you can access the parts of your XML document through its properties and methods. These properties are defined in the DOM specification; this portion of the reference manual describes the interpretation of the specification in Python. The specification provided by the W3C defines the DOM API for Java, ECMAScript, and OMG IDL. The Python mapping defined here is based in large part on the IDL version of the specification, but strict compliance is not required (though implementations are free to support the strict mapping from IDL). See section :ref:`dom-conformance` for a detailed discussion of mapping requirements. .. seealso:: `Document Object Model (DOM) Level 2 Specification <https://www.w3.org/TR/DOM-Level-2-Core/>`_ The W3C recommendation upon which the Python DOM API is based. `Document Object Model (DOM) Level 1 Specification <https://www.w3.org/TR/REC-DOM-Level-1/>`_ The W3C recommendation for the DOM supported by :mod:`xml.dom.minidom`. `Python Language Mapping Specification <http://www.omg.org/spec/PYTH/1.2/PDF>`_ This specifies the mapping from OMG IDL to Python. Module Contents --------------- The :mod:`xml.dom` contains the following functions: .. function:: registerDOMImplementation(name, factory) Register the *factory* function with the name *name*. The factory function should return an object which implements the :class:`DOMImplementation` interface. The factory function can return the same object every time, or a new one for each call, as appropriate for the specific implementation (e.g. if that implementation supports some customization). .. function:: getDOMImplementation([name[, features]]) Return a suitable DOM implementation. The *name* is either well-known, the module name of a DOM implementation, or ``None``. If it is not ``None``, imports the corresponding module and returns a :class:`DOMImplementation` object if the import succeeds. If no name is given, and if the environment variable :envvar:`PYTHON_DOM` is set, this variable is used to find the implementation. If name is not given, this examines the available implementations to find one with the required feature set. If no implementation can be found, raise an :exc:`ImportError`. The features list must be a sequence of ``(feature, version)`` pairs which are passed to the :meth:`hasFeature` method on available :class:`DOMImplementation` objects. Some convenience constants are also provided: .. data:: EMPTY_NAMESPACE The value used to indicate that no namespace is associated with a node in the DOM. This is typically found as the :attr:`namespaceURI` of a node, or used as the *namespaceURI* parameter to a namespaces-specific method. .. versionadded:: 2.2 .. data:: XML_NAMESPACE The namespace URI associated with the reserved prefix ``xml``, as defined by `Namespaces in XML <https://www.w3.org/TR/REC-xml-names/>`_ (section 4). .. versionadded:: 2.2 .. data:: XMLNS_NAMESPACE The namespace URI for namespace declarations, as defined by `Document Object Model (DOM) Level 2 Core Specification <https://www.w3.org/TR/DOM-Level-2-Core/core.html>`_ (section 1.1.8). .. versionadded:: 2.2 .. data:: XHTML_NAMESPACE The URI of the XHTML namespace as defined by `XHTML 1.0: The Extensible HyperText Markup Language <https://www.w3.org/TR/xhtml1/>`_ (section 3.1.1). .. versionadded:: 2.2 In addition, :mod:`xml.dom` contains a base :class:`Node` class and the DOM exception classes. The :class:`Node` class provided by this module does not implement any of the methods or attributes defined by the DOM specification; concrete DOM implementations must provide those. The :class:`Node` class provided as part of this module does provide the constants used for the :attr:`nodeType` attribute on concrete :class:`Node` objects; they are located within the class rather than at the module level to conform with the DOM specifications. .. Should the Node documentation go here? .. _dom-objects: Objects in the DOM ------------------ The definitive documentation for the DOM is the DOM specification from the W3C. Note that DOM attributes may also be manipulated as nodes instead of as simple strings. It is fairly rare that you must do this, however, so this usage is not yet documented. +--------------------------------+-----------------------------------+---------------------------------+ | Interface | Section | Purpose | +================================+===================================+=================================+ | :class:`DOMImplementation` | :ref:`dom-implementation-objects` | Interface to the underlying | | | | implementation. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`Node` | :ref:`dom-node-objects` | Base interface for most objects | | | | in a document. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`NodeList` | :ref:`dom-nodelist-objects` | Interface for a sequence of | | | | nodes. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`DocumentType` | :ref:`dom-documenttype-objects` | Information about the | | | | declarations needed to process | | | | a document. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`Document` | :ref:`dom-document-objects` | Object which represents an | | | | entire document. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`Element` | :ref:`dom-element-objects` | Element nodes in the document | | | | hierarchy. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`Attr` | :ref:`dom-attr-objects` | Attribute value nodes on | | | | element nodes. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`Comment` | :ref:`dom-comment-objects` | Representation of comments in | | | | the source document. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`Text` | :ref:`dom-text-objects` | Nodes containing textual | | | | content from the document. | +--------------------------------+-----------------------------------+---------------------------------+ | :class:`ProcessingInstruction` | :ref:`dom-pi-objects` | Processing instruction | | | | representation. | +--------------------------------+-----------------------------------+---------------------------------+ An additional section describes the exceptions defined for working with the DOM in Python. .. _dom-implementation-objects: DOMImplementation Objects ^^^^^^^^^^^^^^^^^^^^^^^^^ The :class:`DOMImplementation` interface provides a way for applications to determine the availability of particular features in the DOM they are using. DOM Level 2 added the ability to create new :class:`Document` and :class:`DocumentType` objects using the :class:`DOMImplementation` as well. .. method:: DOMImplementation.hasFeature(feature, version) Return true if the feature identified by the pair of strings *feature* and *version* is implemented. .. method:: DOMImplementation.createDocument(namespaceUri, qualifiedName, doctype) Return a new :class:`Document` object (the root of the DOM), with a child :class:`Element` object having the given *namespaceUri* and *qualifiedName*. The *doctype* must be a :class:`DocumentType` object created by :meth:`createDocumentType`, or ``None``. In the Python DOM API, the first two arguments can also be ``None`` in order to indicate that no :class:`Element` child is to be created. .. method:: DOMImplementation.createDocumentType(qualifiedName, publicId, systemId) Return a new :class:`DocumentType` object that encapsulates the given *qualifiedName*, *publicId*, and *systemId* strings, representing the information contained in an XML document type declaration. .. _dom-node-objects: Node Objects ^^^^^^^^^^^^ All of the components of an XML document are subclasses of :class:`Node`. .. attribute:: Node.nodeType An integer representing the node type. Symbolic constants for the types are on the :class:`Node` object: :const:`ELEMENT_NODE`, :const:`ATTRIBUTE_NODE`, :const:`TEXT_NODE`, :const:`CDATA_SECTION_NODE`, :const:`ENTITY_NODE`, :const:`PROCESSING_INSTRUCTION_NODE`, :const:`COMMENT_NODE`, :const:`DOCUMENT_NODE`, :const:`DOCUMENT_TYPE_NODE`, :const:`NOTATION_NODE`. This is a read-only attribute. .. attribute:: Node.parentNode The parent of the current node, or ``None`` for the document node. The value is always a :class:`Node` object or ``None``. For :class:`Element` nodes, this will be the parent element, except for the root element, in which case it will be the :class:`Document` object. For :class:`Attr` nodes, this is always ``None``. This is a read-only attribute. .. attribute:: Node.attributes A :class:`NamedNodeMap` of attribute objects. Only elements have actual values for this; others provide ``None`` for this attribute. This is a read-only attribute. .. attribute:: Node.previousSibling The node that immediately precedes this one with the same parent. For instance the element with an end-tag that comes just before the *self* element's start-tag. Of course, XML documents are made up of more than just elements so the previous sibling could be text, a comment, or something else. If this node is the first child of the parent, this attribute will be ``None``. This is a read-only attribute. .. attribute:: Node.nextSibling The node that immediately follows this one with the same parent. See also :attr:`previousSibling`. If this is the last child of the parent, this attribute will be ``None``. This is a read-only attribute. .. attribute:: Node.childNodes A list of nodes contained within this node. This is a read-only attribute. .. attribute:: Node.firstChild The first child of the node, if there are any, or ``None``. This is a read-only attribute. .. attribute:: Node.lastChild The last child of the node, if there are any, or ``None``. This is a read-only attribute. .. attribute:: Node.localName The part of the :attr:`tagName` following the colon if there is one, else the entire :attr:`tagName`. The value is a string. .. attribute:: Node.prefix The part of the :attr:`tagName` preceding the colon if there is one, else the empty string. The value is a string, or ``None``. .. attribute:: Node.namespaceURI The namespace associated with the element name. This will be a string or ``None``. This is a read-only attribute. .. attribute:: Node.nodeName This has a different meaning for each node type; see the DOM specification for details. You can always get the information you would get here from another property such as the :attr:`tagName` property for elements or the :attr:`name` property for attributes. For all node types, the value of this attribute will be either a string or ``None``. This is a read-only attribute. .. attribute:: Node.nodeValue This has a different meaning for each node type; see the DOM specification for details. The situation is similar to that with :attr:`nodeName`. The value is a string or ``None``. .. method:: Node.hasAttributes() Returns true if the node has any attributes. .. method:: Node.hasChildNodes() Returns true if the node has any child nodes. .. method:: Node.isSameNode(other) Returns true if *other* refers to the same node as this node. This is especially useful for DOM implementations which use any sort of proxy architecture (because more than one object can refer to the same node). .. note:: This is based on a proposed DOM Level 3 API which is still in the "working draft" stage, but this particular interface appears uncontroversial. Changes from the W3C will not necessarily affect this method in the Python DOM interface (though any new W3C API for this would also be supported). .. method:: Node.appendChild(newChild) Add a new child node to this node at the end of the list of children, returning *newChild*. If the node was already in the tree, it is removed first. .. method:: Node.insertBefore(newChild, refChild) Insert a new child node before an existing child. It must be the case that *refChild* is a child of this node; if not, :exc:`ValueError` is raised. *newChild* is returned. If *refChild* is ``None``, it inserts *newChild* at the end of the children's list. .. method:: Node.removeChild(oldChild) Remove a child node. *oldChild* must be a child of this node; if not, :exc:`ValueError` is raised. *oldChild* is returned on success. If *oldChild* will not be used further, its :meth:`unlink` method should be called. .. method:: Node.replaceChild(newChild, oldChild) Replace an existing node with a new node. It must be the case that *oldChild* is a child of this node; if not, :exc:`ValueError` is raised. .. method:: Node.normalize() Join adjacent text nodes so that all stretches of text are stored as single :class:`Text` instances. This simplifies processing text from a DOM tree for many applications. .. versionadded:: 2.1 .. method:: Node.cloneNode(deep) Clone this node. Setting *deep* means to clone all child nodes as well. This returns the clone. .. _dom-nodelist-objects: NodeList Objects ^^^^^^^^^^^^^^^^ A :class:`NodeList` represents a sequence of nodes. These objects are used in two ways in the DOM Core recommendation: an :class:`Element` object provides one as its list of child nodes, and the :meth:`getElementsByTagName` and :meth:`getElementsByTagNameNS` methods of :class:`Node` return objects with this interface to represent query results. The DOM Level 2 recommendation defines one method and one attribute for these objects: .. method:: NodeList.item(i) Return the *i*'th item from the sequence, if there is one, or ``None``. The index *i* is not allowed to be less than zero or greater than or equal to the length of the sequence. .. attribute:: NodeList.length The number of nodes in the sequence. In addition, the Python DOM interface requires that some additional support is provided to allow :class:`NodeList` objects to be used as Python sequences. All :class:`NodeList` implementations must include support for :meth:`~object.__len__` and :meth:`~object.__getitem__`; this allows iteration over the :class:`NodeList` in :keyword:`for` statements and proper support for the :func:`len` built-in function. If a DOM implementation supports modification of the document, the :class:`NodeList` implementation must also support the :meth:`~object.__setitem__` and :meth:`~object.__delitem__` methods. .. _dom-documenttype-objects: DocumentType Objects ^^^^^^^^^^^^^^^^^^^^ Information about the notations and entities declared by a document (including the external subset if the parser uses it and can provide the information) is available from a :class:`DocumentType` object. The :class:`DocumentType` for a document is available from the :class:`Document` object's :attr:`doctype` attribute; if there is no ``DOCTYPE`` declaration for the document, the document's :attr:`doctype` attribute will be set to ``None`` instead of an instance of this interface. :class:`DocumentType` is a specialization of :class:`Node`, and adds the following attributes: .. attribute:: DocumentType.publicId The public identifier for the external subset of the document type definition. This will be a string or ``None``. .. attribute:: DocumentType.systemId The system identifier for the external subset of the document type definition. This will be a URI as a string, or ``None``. .. attribute:: DocumentType.internalSubset A string giving the complete internal subset from the document. This does not include the brackets which enclose the subset. If the document has no internal subset, this should be ``None``. .. attribute:: DocumentType.name The name of the root element as given in the ``DOCTYPE`` declaration, if present. .. attribute:: DocumentType.entities This is a :class:`NamedNodeMap` giving the definitions of external entities. For entity names defined more than once, only the first definition is provided (others are ignored as required by the XML recommendation). This may be ``None`` if the information is not provided by the parser, or if no entities are defined. .. attribute:: DocumentType.notations This is a :class:`NamedNodeMap` giving the definitions of notations. For notation names defined more than once, only the first definition is provided (others are ignored as required by the XML recommendation). This may be ``None`` if the information is not provided by the parser, or if no notations are defined. .. _dom-document-objects: Document Objects ^^^^^^^^^^^^^^^^ A :class:`Document` represents an entire XML document, including its constituent elements, attributes, processing instructions, comments etc. Remember that it inherits properties from :class:`Node`. .. attribute:: Document.documentElement The one and only root element of the document. .. method:: Document.createElement(tagName) Create and return a new element node. The element is not inserted into the document when it is created. You need to explicitly insert it with one of the other methods such as :meth:`insertBefore` or :meth:`appendChild`. .. method:: Document.createElementNS(namespaceURI, tagName) Create and return a new element with a namespace. The *tagName* may have a prefix. The element is not inserted into the document when it is created. You need to explicitly insert it with one of the other methods such as :meth:`insertBefore` or :meth:`appendChild`. .. method:: Document.createTextNode(data) Create and return a text node containing the data passed as a parameter. As with the other creation methods, this one does not insert the node into the tree. .. method:: Document.createComment(data) Create and return a comment node containing the data passed as a parameter. As with the other creation methods, this one does not insert the node into the tree. .. method:: Document.createProcessingInstruction(target, data) Create and return a processing instruction node containing the *target* and *data* passed as parameters. As with the other creation methods, this one does not insert the node into the tree. .. method:: Document.createAttribute(name) Create and return an attribute node. This method does not associate the attribute node with any particular element. You must use :meth:`setAttributeNode` on the appropriate :class:`Element` object to use the newly created attribute instance. .. method:: Document.createAttributeNS(namespaceURI, qualifiedName) Create and return an attribute node with a namespace. The *tagName* may have a prefix. This method does not associate the attribute node with any particular element. You must use :meth:`setAttributeNode` on the appropriate :class:`Element` object to use the newly created attribute instance. .. method:: Document.getElementsByTagName(tagName) Search for all descendants (direct children, children's children, etc.) with a particular element type name. .. method:: Document.getElementsByTagNameNS(namespaceURI, localName) Search for all descendants (direct children, children's children, etc.) with a particular namespace URI and localname. The localname is the part of the namespace after the prefix. .. _dom-element-objects: Element Objects ^^^^^^^^^^^^^^^ :class:`Element` is a subclass of :class:`Node`, so inherits all the attributes of that class. .. attribute:: Element.tagName The element type name. In a namespace-using document it may have colons in it. The value is a string. .. method:: Element.getElementsByTagName(tagName) Same as equivalent method in the :class:`Document` class. .. method:: Element.getElementsByTagNameNS(namespaceURI, localName) Same as equivalent method in the :class:`Document` class. .. method:: Element.hasAttribute(name) Returns true if the element has an attribute named by *name*. .. method:: Element.hasAttributeNS(namespaceURI, localName) Returns true if the element has an attribute named by *namespaceURI* and *localName*. .. method:: Element.getAttribute(name) Return the value of the attribute named by *name* as a string. If no such attribute exists, an empty string is returned, as if the attribute had no value. .. method:: Element.getAttributeNode(attrname) Return the :class:`Attr` node for the attribute named by *attrname*. .. method:: Element.getAttributeNS(namespaceURI, localName) Return the value of the attribute named by *namespaceURI* and *localName* as a string. If no such attribute exists, an empty string is returned, as if the attribute had no value. .. method:: Element.getAttributeNodeNS(namespaceURI, localName) Return an attribute value as a node, given a *namespaceURI* and *localName*. .. method:: Element.removeAttribute(name) Remove an attribute by name. If there is no matching attribute, a :exc:`NotFoundErr` is raised. .. method:: Element.removeAttributeNode(oldAttr) Remove and return *oldAttr* from the attribute list, if present. If *oldAttr* is not present, :exc:`NotFoundErr` is raised. .. method:: Element.removeAttributeNS(namespaceURI, localName) Remove an attribute by name. Note that it uses a localName, not a qname. No exception is raised if there is no matching attribute. .. method:: Element.setAttribute(name, value) Set an attribute value from a string. .. method:: Element.setAttributeNode(newAttr) Add a new attribute node to the element, replacing an existing attribute if necessary if the :attr:`name` attribute matches. If a replacement occurs, the old attribute node will be returned. If *newAttr* is already in use, :exc:`InuseAttributeErr` will be raised. .. method:: Element.setAttributeNodeNS(newAttr) Add a new attribute node to the element, replacing an existing attribute if necessary if the :attr:`namespaceURI` and :attr:`localName` attributes match. If a replacement occurs, the old attribute node will be returned. If *newAttr* is already in use, :exc:`InuseAttributeErr` will be raised. .. method:: Element.setAttributeNS(namespaceURI, qname, value) Set an attribute value from a string, given a *namespaceURI* and a *qname*. Note that a qname is the whole attribute name. This is different than above. .. _dom-attr-objects: Attr Objects ^^^^^^^^^^^^ :class:`Attr` inherits from :class:`Node`, so inherits all its attributes. .. attribute:: Attr.name The attribute name. In a namespace-using document it may include a colon. .. attribute:: Attr.localName The part of the name following the colon if there is one, else the entire name. This is a read-only attribute. .. attribute:: Attr.prefix The part of the name preceding the colon if there is one, else the empty string. .. attribute:: Attr.value The text value of the attribute. This is a synonym for the :attr:`nodeValue` attribute. .. _dom-attributelist-objects: NamedNodeMap Objects ^^^^^^^^^^^^^^^^^^^^ :class:`NamedNodeMap` does *not* inherit from :class:`Node`. .. attribute:: NamedNodeMap.length The length of the attribute list. .. method:: NamedNodeMap.item(index) Return an attribute with a particular index. The order you get the attributes in is arbitrary but will be consistent for the life of a DOM. Each item is an attribute node. Get its value with the :attr:`value` attribute. There are also experimental methods that give this class more mapping behavior. You can use them or you can use the standardized :meth:`getAttribute\*` family of methods on the :class:`Element` objects. .. _dom-comment-objects: Comment Objects ^^^^^^^^^^^^^^^ :class:`Comment` represents a comment in the XML document. It is a subclass of :class:`Node`, but cannot have child nodes. .. attribute:: Comment.data The content of the comment as a string. The attribute contains all characters between the leading ``<!-``\ ``-`` and trailing ``-``\ ``->``, but does not include them. .. _dom-text-objects: Text and CDATASection Objects ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The :class:`Text` interface represents text in the XML document. If the parser and DOM implementation support the DOM's XML extension, portions of the text enclosed in CDATA marked sections are stored in :class:`CDATASection` objects. These two interfaces are identical, but provide different values for the :attr:`nodeType` attribute. These interfaces extend the :class:`Node` interface. They cannot have child nodes. .. attribute:: Text.data The content of the text node as a string. .. note:: The use of a :class:`CDATASection` node does not indicate that the node represents a complete CDATA marked section, only that the content of the node was part of a CDATA section. A single CDATA section may be represented by more than one node in the document tree. There is no way to determine whether two adjacent :class:`CDATASection` nodes represent different CDATA marked sections. .. _dom-pi-objects: ProcessingInstruction Objects ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Represents a processing instruction in the XML document; this inherits from the :class:`Node` interface and cannot have child nodes. .. attribute:: ProcessingInstruction.target The content of the processing instruction up to the first whitespace character. This is a read-only attribute. .. attribute:: ProcessingInstruction.data The content of the processing instruction following the first whitespace character. .. _dom-exceptions: Exceptions ^^^^^^^^^^ .. versionadded:: 2.1 The DOM Level 2 recommendation defines a single exception, :exc:`DOMException`, and a number of constants that allow applications to determine what sort of error occurred. :exc:`DOMException` instances carry a :attr:`code` attribute that provides the appropriate value for the specific exception. The Python DOM interface provides the constants, but also expands the set of exceptions so that a specific exception exists for each of the exception codes defined by the DOM. The implementations must raise the appropriate specific exception, each of which carries the appropriate value for the :attr:`code` attribute. .. exception:: DOMException Base exception class used for all specific DOM exceptions. This exception class cannot be directly instantiated. .. exception:: DomstringSizeErr Raised when a specified range of text does not fit into a string. This is not known to be used in the Python DOM implementations, but may be received from DOM implementations not written in Python. .. exception:: HierarchyRequestErr Raised when an attempt is made to insert a node where the node type is not allowed. .. exception:: IndexSizeErr Raised when an index or size parameter to a method is negative or exceeds the allowed values. .. exception:: InuseAttributeErr Raised when an attempt is made to insert an :class:`Attr` node that is already present elsewhere in the document. .. exception:: InvalidAccessErr Raised if a parameter or an operation is not supported on the underlying object. .. exception:: InvalidCharacterErr This exception is raised when a string parameter contains a character that is not permitted in the context it's being used in by the XML 1.0 recommendation. For example, attempting to create an :class:`Element` node with a space in the element type name will cause this error to be raised. .. exception:: InvalidModificationErr Raised when an attempt is made to modify the type of a node. .. exception:: InvalidStateErr Raised when an attempt is made to use an object that is not defined or is no longer usable. .. exception:: NamespaceErr If an attempt is made to change any object in a way that is not permitted with regard to the `Namespaces in XML <https://www.w3.org/TR/REC-xml-names/>`_ recommendation, this exception is raised. .. exception:: NotFoundErr Exception when a node does not exist in the referenced context. For example, :meth:`NamedNodeMap.removeNamedItem` will raise this if the node passed in does not exist in the map. .. exception:: NotSupportedErr Raised when the implementation does not support the requested type of object or operation. .. exception:: NoDataAllowedErr This is raised if data is specified for a node which does not support data. .. XXX a better explanation is needed! .. exception:: NoModificationAllowedErr Raised on attempts to modify an object where modifications are not allowed (such as for read-only nodes). .. exception:: SyntaxErr Raised when an invalid or illegal string is specified. .. XXX how is this different from InvalidCharacterErr? .. exception:: WrongDocumentErr Raised when a node is inserted in a different document than it currently belongs to, and the implementation does not support migrating the node from one document to the other. The exception codes defined in the DOM recommendation map to the exceptions described above according to this table: +--------------------------------------+---------------------------------+ | Constant | Exception | +======================================+=================================+ | :const:`DOMSTRING_SIZE_ERR` | :exc:`DomstringSizeErr` | +--------------------------------------+---------------------------------+ | :const:`HIERARCHY_REQUEST_ERR` | :exc:`HierarchyRequestErr` | +--------------------------------------+---------------------------------+ | :const:`INDEX_SIZE_ERR` | :exc:`IndexSizeErr` | +--------------------------------------+---------------------------------+ | :const:`INUSE_ATTRIBUTE_ERR` | :exc:`InuseAttributeErr` | +--------------------------------------+---------------------------------+ | :const:`INVALID_ACCESS_ERR` | :exc:`InvalidAccessErr` | +--------------------------------------+---------------------------------+ | :const:`INVALID_CHARACTER_ERR` | :exc:`InvalidCharacterErr` | +--------------------------------------+---------------------------------+ | :const:`INVALID_MODIFICATION_ERR` | :exc:`InvalidModificationErr` | +--------------------------------------+---------------------------------+ | :const:`INVALID_STATE_ERR` | :exc:`InvalidStateErr` | +--------------------------------------+---------------------------------+ | :const:`NAMESPACE_ERR` | :exc:`NamespaceErr` | +--------------------------------------+---------------------------------+ | :const:`NOT_FOUND_ERR` | :exc:`NotFoundErr` | +--------------------------------------+---------------------------------+ | :const:`NOT_SUPPORTED_ERR` | :exc:`NotSupportedErr` | +--------------------------------------+---------------------------------+ | :const:`NO_DATA_ALLOWED_ERR` | :exc:`NoDataAllowedErr` | +--------------------------------------+---------------------------------+ | :const:`NO_MODIFICATION_ALLOWED_ERR` | :exc:`NoModificationAllowedErr` | +--------------------------------------+---------------------------------+ | :const:`SYNTAX_ERR` | :exc:`SyntaxErr` | +--------------------------------------+---------------------------------+ | :const:`WRONG_DOCUMENT_ERR` | :exc:`WrongDocumentErr` | +--------------------------------------+---------------------------------+ .. _dom-conformance: Conformance ----------- This section describes the conformance requirements and relationships between the Python DOM API, the W3C DOM recommendations, and the OMG IDL mapping for Python. .. _dom-type-mapping: Type Mapping ^^^^^^^^^^^^ The primitive IDL types used in the DOM specification are mapped to Python types according to the following table. +------------------+-------------------------------------------+ | IDL Type | Python Type | +==================+===========================================+ | ``boolean`` | ``IntegerType`` (with a value of ``0`` or | | | ``1``) | +------------------+-------------------------------------------+ | ``int`` | ``IntegerType`` | +------------------+-------------------------------------------+ | ``long int`` | ``IntegerType`` | +------------------+-------------------------------------------+ | ``unsigned int`` | ``IntegerType`` | +------------------+-------------------------------------------+ Additionally, the :class:`DOMString` defined in the recommendation is mapped to a Python string or Unicode string. Applications should be able to handle Unicode whenever a string is returned from the DOM. The IDL ``null`` value is mapped to ``None``, which may be accepted or provided by the implementation whenever ``null`` is allowed by the API. .. _dom-accessor-methods: Accessor Methods ^^^^^^^^^^^^^^^^ The mapping from OMG IDL to Python defines accessor functions for IDL ``attribute`` declarations in much the way the Java mapping does. Mapping the IDL declarations :: readonly attribute string someValue; attribute string anotherValue; yields three accessor functions: a "get" method for :attr:`someValue` (:meth:`_get_someValue`), and "get" and "set" methods for :attr:`anotherValue` (:meth:`_get_anotherValue` and :meth:`_set_anotherValue`). The mapping, in particular, does not require that the IDL attributes are accessible as normal Python attributes: ``object.someValue`` is *not* required to work, and may raise an :exc:`AttributeError`. The Python DOM API, however, *does* require that normal attribute access work. This means that the typical surrogates generated by Python IDL compilers are not likely to work, and wrapper objects may be needed on the client if the DOM objects are accessed via CORBA. While this does require some additional consideration for CORBA DOM clients, the implementers with experience using DOM over CORBA from Python do not consider this a problem. Attributes that are declared ``readonly`` may not restrict write access in all DOM implementations. In the Python DOM API, accessor functions are not required. If provided, they should take the form defined by the Python IDL mapping, but these methods are considered unnecessary since the attributes are accessible directly from Python. "Set" accessors should never be provided for ``readonly`` attributes. The IDL definitions do not fully embody the requirements of the W3C DOM API, such as the notion of certain objects, such as the return value of :meth:`getElementsByTagName`, being "live". The Python DOM API does not require implementations to enforce such requirements.
Save
cmd:
run