/
usr
/
share
/
doc
/
python3-docs
/
html
/
library
/
/usr/share/doc/python3-docs/html/library
mkdir
upload
Name
Size
Mode
Actions
2to3.html
61709
0644
edit
dl
rm
abc.html
41394
0644
edit
dl
rm
aifc.html
28114
0644
edit
dl
rm
allos.html
32236
0644
edit
dl
rm
archiving.html
11992
0644
edit
dl
rm
argparse.html
274984
0644
edit
dl
rm
array.html
33547
0644
edit
dl
rm
ast.html
39595
0644
edit
dl
rm
asynchat.html
32546
0644
edit
dl
rm
asyncio-dev.html
51869
0644
edit
dl
rm
asyncio-eventloop.html
111215
0644
edit
dl
rm
asyncio-eventloops.html
33026
0644
edit
dl
rm
asyncio-protocol.html
87431
0644
edit
dl
rm
asyncio-queue.html
23957
0644
edit
dl
rm
asyncio-stream.html
61005
0644
edit
dl
rm
asyncio-subprocess.html
58015
0644
edit
dl
rm
asyncio-sync.html
35678
0644
edit
dl
rm
asyncio-task.html
83968
0644
edit
dl
rm
asyncio.html
28026
0644
edit
dl
rm
asyncore.html
42706
0644
edit
dl
rm
atexit.html
18433
0644
edit
dl
rm
audioop.html
35442
0644
edit
dl
rm
base64.html
36454
0644
edit
dl
rm
bdb.html
43423
0644
edit
dl
rm
binary.html
12723
0644
edit
dl
rm
binascii.html
24745
0644
edit
dl
rm
binhex.html
11669
0644
edit
dl
rm
bisect.html
25602
0644
edit
dl
rm
builtins.html
11604
0644
edit
dl
rm
bz2.html
33358
0644
edit
dl
rm
calendar.html
39539
0644
edit
dl
rm
cgi.html
55881
0644
edit
dl
rm
cgitb.html
12765
0644
edit
dl
rm
chunk.html
16872
0644
edit
dl
rm
cmath.html
34171
0644
edit
dl
rm
cmd.html
43811
0644
edit
dl
rm
code.html
27886
0644
edit
dl
rm
codecs.html
134071
0644
edit
dl
rm
codeop.html
14304
0644
edit
dl
rm
collections.abc.html
60912
0644
edit
dl
rm
collections.html
154946
0644
edit
dl
rm
colorsys.html
12627
0644
edit
dl
rm
compileall.html
28263
0644
edit
dl
rm
concurrency.html
21203
0644
edit
dl
rm
concurrent.futures.html
60660
0644
edit
dl
rm
concurrent.html
7959
0644
edit
dl
rm
configparser.html
141052
0644
edit
dl
rm
constants.html
17500
0644
edit
dl
rm
contextlib.html
88801
0644
edit
dl
rm
copy.html
13841
0644
edit
dl
rm
copyreg.html
14725
0644
edit
dl
rm
crypt.html
20331
0644
edit
dl
rm
crypto.html
10914
0644
edit
dl
rm
csv.html
69043
0644
edit
dl
rm
ctypes.html
264529
0644
edit
dl
rm
curses.ascii.html
25197
0644
edit
dl
rm
curses.html
175551
0644
edit
dl
rm
curses.panel.html
16706
0644
edit
dl
rm
custominterp.html
8734
0644
edit
dl
rm
datatypes.html
23950
0644
edit
dl
rm
datetime.html
306435
0644
edit
dl
rm
dbm.html
43119
0644
edit
dl
rm
debug.html
13983
0644
edit
dl
rm
decimal.html
233486
0644
edit
dl
rm
development.html
25123
0644
edit
dl
rm
difflib.html
96156
0644
edit
dl
rm
dis.html
106191
0644
edit
dl
rm
distribution.html
10506
0644
edit
dl
rm
distutils.html
10884
0644
edit
dl
rm
doctest.html
179752
0644
edit
dl
rm
dummy_threading.html
9316
0644
edit
dl
rm
email.charset.html
26431
0644
edit
dl
rm
email.compat32-message.html
86150
0644
edit
dl
rm
email.contentmanager.html
30028
0644
edit
dl
rm
email.encoders.html
14250
0644
edit
dl
rm
email.errors.html
19704
0644
edit
dl
rm
email.examples.html
57872
0644
edit
dl
rm
email.generator.html
41798
0644
edit
dl
rm
email.header.html
31219
0644
edit
dl
rm
email.headerregistry.html
57670
0644
edit
dl
rm
email.html
27741
0644
edit
dl
rm
email.iterators.html
13532
0644
edit
dl
rm
email.message.html
87210
0644
edit
dl
rm
email.mime.html
36081
0644
edit
dl
rm
email.parser.html
47430
0644
edit
dl
rm
email.policy.html
75241
0644
edit
dl
rm
email.util.html
33853
0644
edit
dl
rm
ensurepip.html
18700
0644
edit
dl
rm
enum.html
133949
0644
edit
dl
rm
errno.html
41331
0644
edit
dl
rm
exceptions.html
85151
0644
edit
dl
rm
faulthandler.html
23396
0644
edit
dl
rm
fcntl.html
27321
0644
edit
dl
rm
filecmp.html
25036
0644
edit
dl
rm
fileformats.html
11129
0644
edit
dl
rm
fileinput.html
30030
0644
edit
dl
rm
filesys.html
13418
0644
edit
dl
rm
fnmatch.html
16987
0644
edit
dl
rm
formatter.html
37666
0644
edit
dl
rm
fpectl.html
17538
0644
edit
dl
rm
fractions.html
29918
0644
edit
dl
rm
frameworks.html
13471
0644
edit
dl
rm
ftplib.html
54429
0644
edit
dl
rm
functional.html
9002
0644
edit
dl
rm
functions.html
201486
0644
edit
dl
rm
functools.html
64951
0644
edit
dl
rm
gc.html
29524
0644
edit
dl
rm
getopt.html
25353
0644
edit
dl
rm
getpass.html
12061
0644
edit
dl
rm
gettext.html
76641
0644
edit
dl
rm
glob.html
18432
0644
edit
dl
rm
grp.html
12383
0644
edit
dl
rm
gzip.html
32669
0644
edit
dl
rm
hashlib.html
79554
0644
edit
dl
rm
heapq.html
35529
0644
edit
dl
rm
hmac.html
17827
0644
edit
dl
rm
html.entities.html
11361
0644
edit
dl
rm
html.html
11108
0644
edit
dl
rm
html.parser.html
41842
0644
edit
dl
rm
http.client.html
65250
0644
edit
dl
rm
http.cookiejar.html
96195
0644
edit
dl
rm
http.cookies.html
39329
0644
edit
dl
rm
http.html
37602
0644
edit
dl
rm
http.server.html
58191
0644
edit
dl
rm
i18n.html
10464
0644
edit
dl
rm
idle.html
48412
0644
edit
dl
rm
imaplib.html
67339
0644
edit
dl
rm
imghdr.html
13456
0644
edit
dl
rm
imp.html
48153
0644
edit
dl
rm
importlib.html
173109
0644
edit
dl
rm
index.html
67768
0644
edit
dl
rm
inspect.html
130355
0644
edit
dl
rm
internet.html
31087
0644
edit
dl
rm
intro.html
9904
0644
edit
dl
rm
io.html
122685
0644
edit
dl
rm
ipaddress.html
105873
0644
edit
dl
rm
ipc.html
33743
0644
edit
dl
rm
itertools.html
132824
0644
edit
dl
rm
json.html
81078
0644
edit
dl
rm
keyword.html
8918
0644
edit
dl
rm
language.html
13648
0644
edit
dl
rm
linecache.html
13492
0644
edit
dl
rm
locale.html
61540
0644
edit
dl
rm
logging.config.html
85489
0644
edit
dl
rm
logging.handlers.html
112397
0644
edit
dl
rm
logging.html
134850
0644
edit
dl
rm
lzma.html
56484
0644
edit
dl
rm
macpath.html
9257
0644
edit
dl
rm
mailbox.html
157315
0644
edit
dl
rm
mailcap.html
14676
0644
edit
dl
rm
markup.html
19356
0644
edit
dl
rm
marshal.html
18317
0644
edit
dl
rm
math.html
53661
0644
edit
dl
rm
mimetypes.html
31410
0644
edit
dl
rm
misc.html
8123
0644
edit
dl
rm
mm.html
10022
0644
edit
dl
rm
mmap.html
34294
0644
edit
dl
rm
modulefinder.html
18559
0644
edit
dl
rm
modules.html
10914
0644
edit
dl
rm
msilib.html
57205
0644
edit
dl
rm
msvcrt.html
21989
0644
edit
dl
rm
multiprocessing.html
365487
0644
edit
dl
rm
netdata.html
17470
0644
edit
dl
rm
netrc.html
14568
0644
edit
dl
rm
nis.html
11659
0644
edit
dl
rm
nntplib.html
69601
0644
edit
dl
rm
numbers.html
41432
0644
edit
dl
rm
numeric.html
15535
0644
edit
dl
rm
operator.html
81460
0644
edit
dl
rm
optparse.html
249942
0644
edit
dl
rm
os.html
398039
0644
edit
dl
rm
os.path.html
53818
0644
edit
dl
rm
ossaudiodev.html
47947
0644
edit
dl
rm
othergui.html
10256
0644
edit
dl
rm
parser.html
42408
0644
edit
dl
rm
pathlib.html
116726
0644
edit
dl
rm
pdb.html
52661
0644
edit
dl
rm
persistence.html
15281
0644
edit
dl
rm
pickle.html
115052
0644
edit
dl
rm
pickletools.html
17094
0644
edit
dl
rm
pipes.html
15991
0644
edit
dl
rm
pkgutil.html
31878
0644
edit
dl
rm
platform.html
33728
0644
edit
dl
rm
plistlib.html
29290
0644
edit
dl
rm
poplib.html
30940
0644
edit
dl
rm
posix.html
17608
0644
edit
dl
rm
pprint.html
41969
0644
edit
dl
rm
profile.html
71848
0644
edit
dl
rm
pty.html
17594
0644
edit
dl
rm
pwd.html
13098
0644
edit
dl
rm
pyclbr.html
16520
0644
edit
dl
rm
pydoc.html
15991
0644
edit
dl
rm
pyexpat.html
88938
0644
edit
dl
rm
python.html
17133
0644
edit
dl
rm
py_compile.html
15508
0644
edit
dl
rm
queue.html
28199
0644
edit
dl
rm
quopri.html
13858
0644
edit
dl
rm
random.html
60646
0644
edit
dl
rm
re.html
191176
0644
edit
dl
rm
readline.html
42133
0644
edit
dl
rm
reprlib.html
24964
0644
edit
dl
rm
resource.html
36552
0644
edit
dl
rm
rlcompleter.html
14392
0644
edit
dl
rm
runpy.html
26607
0644
edit
dl
rm
sched.html
20034
0644
edit
dl
rm
secrets.html
24734
0644
edit
dl
rm
select.html
62819
0644
edit
dl
rm
selectors.html
35845
0644
edit
dl
rm
shelve.html
28777
0644
edit
dl
rm
shlex.html
48979
0644
edit
dl
rm
shutil.html
74207
0644
edit
dl
rm
signal.html
55064
0644
edit
dl
rm
site.html
32242
0644
edit
dl
rm
smtpd.html
35892
0644
edit
dl
rm
smtplib.html
68433
0644
edit
dl
rm
sndhdr.html
12439
0644
edit
dl
rm
socket.html
196077
0644
edit
dl
rm
socketserver.html
81918
0644
edit
dl
rm
spwd.html
12328
0644
edit
dl
rm
sqlite3.html
161872
0644
edit
dl
rm
ssl.html
266327
0644
edit
dl
rm
stat.html
44722
0644
edit
dl
rm
statistics.html
50050
0644
edit
dl
rm
stdtypes.html
465658
0644
edit
dl
rm
string.html
95262
0644
edit
dl
rm
stringprep.html
18654
0644
edit
dl
rm
struct.html
51100
0644
edit
dl
rm
subprocess.html
141926
0644
edit
dl
rm
sunau.html
31757
0644
edit
dl
rm
superseded.html
13781
0644
edit
dl
rm
symbol.html
8848
0644
edit
dl
rm
symtable.html
26112
0644
edit
dl
rm
sys.html
141670
0644
edit
dl
rm
sysconfig.html
30259
0644
edit
dl
rm
syslog.html
21026
0644
edit
dl
rm
tabnanny.html
12269
0644
edit
dl
rm
tarfile.html
96758
0644
edit
dl
rm
telnetlib.html
30409
0644
edit
dl
rm
tempfile.html
41394
0644
edit
dl
rm
termios.html
18181
0644
edit
dl
rm
test.html
78555
0644
edit
dl
rm
text.html
13786
0644
edit
dl
rm
textwrap.html
37998
0644
edit
dl
rm
threading.html
103464
0644
edit
dl
rm
time.html
79629
0644
edit
dl
rm
timeit.html
45249
0644
edit
dl
rm
tk.html
23299
0644
edit
dl
rm
tkinter.html
82932
0644
edit
dl
rm
tkinter.scrolledtext.html
9957
0644
edit
dl
rm
tkinter.tix.html
51858
0644
edit
dl
rm
tkinter.ttk.html
110673
0644
edit
dl
rm
token.html
22660
0644
edit
dl
rm
tokenize.html
32149
0644
edit
dl
rm
trace.html
29145
0644
edit
dl
rm
traceback.html
57588
0644
edit
dl
rm
tracemalloc.html
101144
0644
edit
dl
rm
tty.html
10540
0644
edit
dl
rm
turtle.html
250367
0644
edit
dl
rm
types.html
37060
0644
edit
dl
rm
typing.html
139175
0644
edit
dl
rm
undoc.html
9181
0644
edit
dl
rm
unicodedata.html
21108
0644
edit
dl
rm
unittest.html
250689
0644
edit
dl
rm
unittest.mock-examples.html
168144
0644
edit
dl
rm
unittest.mock.html
300089
0644
edit
dl
rm
unix.html
11780
0644
edit
dl
rm
urllib.error.html
14474
0644
edit
dl
rm
urllib.html
9566
0644
edit
dl
rm
urllib.parse.html
76334
0644
edit
dl
rm
urllib.request.html
177199
0644
edit
dl
rm
urllib.robotparser.html
17156
0644
edit
dl
rm
uu.html
12209
0644
edit
dl
rm
uuid.html
31957
0644
edit
dl
rm
venv.html
73909
0644
edit
dl
rm
warnings.html
50320
0644
edit
dl
rm
wave.html
29868
0644
edit
dl
rm
weakref.html
65292
0644
edit
dl
rm
webbrowser.html
26901
0644
edit
dl
rm
windows.html
10626
0644
edit
dl
rm
winreg.html
66730
0644
edit
dl
rm
winsound.html
21268
0644
edit
dl
rm
wsgiref.html
94492
0644
edit
dl
rm
xdrlib.html
33751
0644
edit
dl
rm
xml.dom.html
97570
0644
edit
dl
rm
xml.dom.minidom.html
41481
0644
edit
dl
rm
xml.dom.pulldom.html
24214
0644
edit
dl
rm
xml.etree.elementtree.html
135491
0644
edit
dl
rm
xml.html
19261
0644
edit
dl
rm
xml.sax.handler.html
42659
0644
edit
dl
rm
xml.sax.html
25515
0644
edit
dl
rm
xml.sax.reader.html
45869
0644
edit
dl
rm
xml.sax.utils.html
16928
0644
edit
dl
rm
xmlrpc.client.html
71947
0644
edit
dl
rm
xmlrpc.html
8535
0644
edit
dl
rm
xmlrpc.server.html
49195
0644
edit
dl
rm
zipapp.html
45105
0644
edit
dl
rm
zipfile.html
80039
0644
edit
dl
rm
zipimport.html
23052
0644
edit
dl
rm
zlib.html
34557
0644
edit
dl
rm
_dummy_thread.html
9193
0644
edit
dl
rm
_thread.html
22588
0644
edit
dl
rm
__future__.html
15792
0644
edit
dl
rm
__main__.html
9019
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-docs/html/library/xml.dom.html
(97570B)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>20.6. xml.dom — The Document Object Model API — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="20.7. xml.dom.minidom — Minimal DOM implementation" href="xml.dom.minidom.html" /> <link rel="prev" title="20.5. xml.etree.ElementTree — The ElementTree XML API" href="xml.etree.elementtree.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/xml.dom.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="xml.dom.minidom.html" title="20.7. xml.dom.minidom — Minimal DOM implementation" accesskey="N">next</a> |</li> <li class="right" > <a href="xml.etree.elementtree.html" title="20.5. xml.etree.ElementTree — The ElementTree XML API" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="markup.html" accesskey="U">20. Structured Markup Processing Tools</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-xml.dom"> <span id="xml-dom-the-document-object-model-api"></span><h1>20.6. <a class="reference internal" href="#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code></a> — The Document Object Model API<a class="headerlink" href="#module-xml.dom" title="Permalink to this headline">¶</a></h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/xml/dom/__init__.py">Lib/xml/dom/__init__.py</a></p> <hr class="docutils" /> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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 <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> object class which provides access to <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> 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 <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object. In Python, each DOM implementation will provide a function <a class="reference internal" href="#xml.dom.getDOMImplementation" title="xml.dom.getDOMImplementation"><code class="xref py py-func docutils literal notranslate"><span class="pre">getDOMImplementation()</span></code></a>. 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.</p> <p>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.</p> <p>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 <a class="reference internal" href="#dom-conformance"><span class="std std-ref">Conformance</span></a> for a detailed discussion of mapping requirements.</p> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="https://www.w3.org/TR/DOM-Level-2-Core/">Document Object Model (DOM) Level 2 Specification</a></dt> <dd>The W3C recommendation upon which the Python DOM API is based.</dd> <dt><a class="reference external" href="https://www.w3.org/TR/REC-DOM-Level-1/">Document Object Model (DOM) Level 1 Specification</a></dt> <dd>The W3C recommendation for the DOM supported by <a class="reference internal" href="xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a>.</dd> <dt><a class="reference external" href="http://www.omg.org/spec/PYTH/1.2/PDF">Python Language Mapping Specification</a></dt> <dd>This specifies the mapping from OMG IDL to Python.</dd> </dl> </div> <div class="section" id="module-contents"> <h2>20.6.1. Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code></a> contains the following functions:</p> <dl class="function"> <dt id="xml.dom.registerDOMImplementation"> <code class="descclassname">xml.dom.</code><code class="descname">registerDOMImplementation</code><span class="sig-paren">(</span><em>name</em>, <em>factory</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.registerDOMImplementation" title="Permalink to this definition">¶</a></dt> <dd><p>Register the <em>factory</em> function with the name <em>name</em>. The factory function should return an object which implements the <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> 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).</p> </dd></dl> <dl class="function"> <dt id="xml.dom.getDOMImplementation"> <code class="descclassname">xml.dom.</code><code class="descname">getDOMImplementation</code><span class="sig-paren">(</span><em>name=None</em>, <em>features=()</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.getDOMImplementation" title="Permalink to this definition">¶</a></dt> <dd><p>Return a suitable DOM implementation. The <em>name</em> is either well-known, the module name of a DOM implementation, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. If it is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, imports the corresponding module and returns a <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> object if the import succeeds. If no name is given, and if the environment variable <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_DOM</span></code> is set, this variable is used to find the implementation.</p> <p>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 <a class="reference internal" href="exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>. The features list must be a sequence of <code class="docutils literal notranslate"><span class="pre">(feature,</span> <span class="pre">version)</span></code> pairs which are passed to the <code class="xref py py-meth docutils literal notranslate"><span class="pre">hasFeature()</span></code> method on available <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> objects.</p> </dd></dl> <p>Some convenience constants are also provided:</p> <dl class="data"> <dt id="xml.dom.EMPTY_NAMESPACE"> <code class="descclassname">xml.dom.</code><code class="descname">EMPTY_NAMESPACE</code><a class="headerlink" href="#xml.dom.EMPTY_NAMESPACE" title="Permalink to this definition">¶</a></dt> <dd><p>The value used to indicate that no namespace is associated with a node in the DOM. This is typically found as the <code class="xref py py-attr docutils literal notranslate"><span class="pre">namespaceURI</span></code> of a node, or used as the <em>namespaceURI</em> parameter to a namespaces-specific method.</p> </dd></dl> <dl class="data"> <dt id="xml.dom.XML_NAMESPACE"> <code class="descclassname">xml.dom.</code><code class="descname">XML_NAMESPACE</code><a class="headerlink" href="#xml.dom.XML_NAMESPACE" title="Permalink to this definition">¶</a></dt> <dd><p>The namespace URI associated with the reserved prefix <code class="docutils literal notranslate"><span class="pre">xml</span></code>, as defined by <a class="reference external" href="https://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a> (section 4).</p> </dd></dl> <dl class="data"> <dt id="xml.dom.XMLNS_NAMESPACE"> <code class="descclassname">xml.dom.</code><code class="descname">XMLNS_NAMESPACE</code><a class="headerlink" href="#xml.dom.XMLNS_NAMESPACE" title="Permalink to this definition">¶</a></dt> <dd><p>The namespace URI for namespace declarations, as defined by <a class="reference external" href="https://www.w3.org/TR/DOM-Level-2-Core/core.html">Document Object Model (DOM) Level 2 Core Specification</a> (section 1.1.8).</p> </dd></dl> <dl class="data"> <dt id="xml.dom.XHTML_NAMESPACE"> <code class="descclassname">xml.dom.</code><code class="descname">XHTML_NAMESPACE</code><a class="headerlink" href="#xml.dom.XHTML_NAMESPACE" title="Permalink to this definition">¶</a></dt> <dd><p>The URI of the XHTML namespace as defined by <a class="reference external" href="https://www.w3.org/TR/xhtml1/">XHTML 1.0: The Extensible HyperText Markup Language</a> (section 3.1.1).</p> </dd></dl> <p>In addition, <a class="reference internal" href="#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom</span></code></a> contains a base <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> class and the DOM exception classes. The <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> 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 <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> class provided as part of this module does provide the constants used for the <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeType</span></code> attribute on concrete <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> objects; they are located within the class rather than at the module level to conform with the DOM specifications.</p> </div> <div class="section" id="objects-in-the-dom"> <span id="dom-objects"></span><h2>20.6.2. Objects in the DOM<a class="headerlink" href="#objects-in-the-dom" title="Permalink to this headline">¶</a></h2> <p>The definitive documentation for the DOM is the DOM specification from the W3C.</p> <p>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.</p> <table border="1" class="docutils"> <colgroup> <col width="32%" /> <col width="35%" /> <col width="33%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Interface</th> <th class="head">Section</th> <th class="head">Purpose</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code></td> <td><a class="reference internal" href="#dom-implementation-objects"><span class="std std-ref">DOMImplementation Objects</span></a></td> <td>Interface to the underlying implementation.</td> </tr> <tr class="row-odd"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code></td> <td><a class="reference internal" href="#dom-node-objects"><span class="std std-ref">Node Objects</span></a></td> <td>Base interface for most objects in a document.</td> </tr> <tr class="row-even"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code></td> <td><a class="reference internal" href="#dom-nodelist-objects"><span class="std std-ref">NodeList Objects</span></a></td> <td>Interface for a sequence of nodes.</td> </tr> <tr class="row-odd"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code></td> <td><a class="reference internal" href="#dom-documenttype-objects"><span class="std std-ref">DocumentType Objects</span></a></td> <td>Information about the declarations needed to process a document.</td> </tr> <tr class="row-even"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code></td> <td><a class="reference internal" href="#dom-document-objects"><span class="std std-ref">Document Objects</span></a></td> <td>Object which represents an entire document.</td> </tr> <tr class="row-odd"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></td> <td><a class="reference internal" href="#dom-element-objects"><span class="std std-ref">Element Objects</span></a></td> <td>Element nodes in the document hierarchy.</td> </tr> <tr class="row-even"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code></td> <td><a class="reference internal" href="#dom-attr-objects"><span class="std std-ref">Attr Objects</span></a></td> <td>Attribute value nodes on element nodes.</td> </tr> <tr class="row-odd"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">Comment</span></code></td> <td><a class="reference internal" href="#dom-comment-objects"><span class="std std-ref">Comment Objects</span></a></td> <td>Representation of comments in the source document.</td> </tr> <tr class="row-even"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">Text</span></code></td> <td><a class="reference internal" href="#dom-text-objects"><span class="std std-ref">Text and CDATASection Objects</span></a></td> <td>Nodes containing textual content from the document.</td> </tr> <tr class="row-odd"><td><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessingInstruction</span></code></td> <td><a class="reference internal" href="#dom-pi-objects"><span class="std std-ref">ProcessingInstruction Objects</span></a></td> <td>Processing instruction representation.</td> </tr> </tbody> </table> <p>An additional section describes the exceptions defined for working with the DOM in Python.</p> <div class="section" id="domimplementation-objects"> <span id="dom-implementation-objects"></span><h3>20.6.2.1. DOMImplementation Objects<a class="headerlink" href="#domimplementation-objects" title="Permalink to this headline">¶</a></h3> <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> 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 <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> and <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> objects using the <code class="xref py py-class docutils literal notranslate"><span class="pre">DOMImplementation</span></code> as well.</p> <dl class="method"> <dt id="xml.dom.DOMImplementation.hasFeature"> <code class="descclassname">DOMImplementation.</code><code class="descname">hasFeature</code><span class="sig-paren">(</span><em>feature</em>, <em>version</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.DOMImplementation.hasFeature" title="Permalink to this definition">¶</a></dt> <dd><p>Return true if the feature identified by the pair of strings <em>feature</em> and <em>version</em> is implemented.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.DOMImplementation.createDocument"> <code class="descclassname">DOMImplementation.</code><code class="descname">createDocument</code><span class="sig-paren">(</span><em>namespaceUri</em>, <em>qualifiedName</em>, <em>doctype</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.DOMImplementation.createDocument" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object (the root of the DOM), with a child <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object having the given <em>namespaceUri</em> and <em>qualifiedName</em>. The <em>doctype</em> must be a <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> object created by <a class="reference internal" href="#xml.dom.DOMImplementation.createDocumentType" title="xml.dom.DOMImplementation.createDocumentType"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createDocumentType()</span></code></a>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. In the Python DOM API, the first two arguments can also be <code class="docutils literal notranslate"><span class="pre">None</span></code> in order to indicate that no <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> child is to be created.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.DOMImplementation.createDocumentType"> <code class="descclassname">DOMImplementation.</code><code class="descname">createDocumentType</code><span class="sig-paren">(</span><em>qualifiedName</em>, <em>publicId</em>, <em>systemId</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.DOMImplementation.createDocumentType" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> object that encapsulates the given <em>qualifiedName</em>, <em>publicId</em>, and <em>systemId</em> strings, representing the information contained in an XML document type declaration.</p> </dd></dl> </div> <div class="section" id="node-objects"> <span id="dom-node-objects"></span><h3>20.6.2.2. Node Objects<a class="headerlink" href="#node-objects" title="Permalink to this headline">¶</a></h3> <p>All of the components of an XML document are subclasses of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>.</p> <dl class="attribute"> <dt id="xml.dom.Node.nodeType"> <code class="descclassname">Node.</code><code class="descname">nodeType</code><a class="headerlink" href="#xml.dom.Node.nodeType" title="Permalink to this definition">¶</a></dt> <dd><p>An integer representing the node type. Symbolic constants for the types are on the <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> object: <code class="xref py py-const docutils literal notranslate"><span class="pre">ELEMENT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ATTRIBUTE_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">TEXT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">CDATA_SECTION_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ENTITY_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">PROCESSING_INSTRUCTION_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">COMMENT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">DOCUMENT_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">DOCUMENT_TYPE_NODE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTATION_NODE</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.parentNode"> <code class="descclassname">Node.</code><code class="descname">parentNode</code><a class="headerlink" href="#xml.dom.Node.parentNode" title="Permalink to this definition">¶</a></dt> <dd><p>The parent of the current node, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for the document node. The value is always a <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> object or <code class="docutils literal notranslate"><span class="pre">None</span></code>. For <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> nodes, this will be the parent element, except for the root element, in which case it will be the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object. For <code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> nodes, this is always <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.attributes"> <code class="descclassname">Node.</code><code class="descname">attributes</code><a class="headerlink" href="#xml.dom.Node.attributes" title="Permalink to this definition">¶</a></dt> <dd><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> of attribute objects. Only elements have actual values for this; others provide <code class="docutils literal notranslate"><span class="pre">None</span></code> for this attribute. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.previousSibling"> <code class="descclassname">Node.</code><code class="descname">previousSibling</code><a class="headerlink" href="#xml.dom.Node.previousSibling" title="Permalink to this definition">¶</a></dt> <dd><p>The node that immediately precedes this one with the same parent. For instance the element with an end-tag that comes just before the <em>self</em> 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 <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.nextSibling"> <code class="descclassname">Node.</code><code class="descname">nextSibling</code><a class="headerlink" href="#xml.dom.Node.nextSibling" title="Permalink to this definition">¶</a></dt> <dd><p>The node that immediately follows this one with the same parent. See also <a class="reference internal" href="#xml.dom.Node.previousSibling" title="xml.dom.Node.previousSibling"><code class="xref py py-attr docutils literal notranslate"><span class="pre">previousSibling</span></code></a>. If this is the last child of the parent, this attribute will be <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.childNodes"> <code class="descclassname">Node.</code><code class="descname">childNodes</code><a class="headerlink" href="#xml.dom.Node.childNodes" title="Permalink to this definition">¶</a></dt> <dd><p>A list of nodes contained within this node. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.firstChild"> <code class="descclassname">Node.</code><code class="descname">firstChild</code><a class="headerlink" href="#xml.dom.Node.firstChild" title="Permalink to this definition">¶</a></dt> <dd><p>The first child of the node, if there are any, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.lastChild"> <code class="descclassname">Node.</code><code class="descname">lastChild</code><a class="headerlink" href="#xml.dom.Node.lastChild" title="Permalink to this definition">¶</a></dt> <dd><p>The last child of the node, if there are any, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.localName"> <code class="descclassname">Node.</code><code class="descname">localName</code><a class="headerlink" href="#xml.dom.Node.localName" title="Permalink to this definition">¶</a></dt> <dd><p>The part of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code> following the colon if there is one, else the entire <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code>. The value is a string.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.prefix"> <code class="descclassname">Node.</code><code class="descname">prefix</code><a class="headerlink" href="#xml.dom.Node.prefix" title="Permalink to this definition">¶</a></dt> <dd><p>The part of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code> preceding the colon if there is one, else the empty string. The value is a string, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.namespaceURI"> <code class="descclassname">Node.</code><code class="descname">namespaceURI</code><a class="headerlink" href="#xml.dom.Node.namespaceURI" title="Permalink to this definition">¶</a></dt> <dd><p>The namespace associated with the element name. This will be a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.nodeName"> <code class="descclassname">Node.</code><code class="descname">nodeName</code><a class="headerlink" href="#xml.dom.Node.nodeName" title="Permalink to this definition">¶</a></dt> <dd><p>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 <code class="xref py py-attr docutils literal notranslate"><span class="pre">tagName</span></code> property for elements or the <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> property for attributes. For all node types, the value of this attribute will be either a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Node.nodeValue"> <code class="descclassname">Node.</code><code class="descname">nodeValue</code><a class="headerlink" href="#xml.dom.Node.nodeValue" title="Permalink to this definition">¶</a></dt> <dd><p>This has a different meaning for each node type; see the DOM specification for details. The situation is similar to that with <a class="reference internal" href="#xml.dom.Node.nodeName" title="xml.dom.Node.nodeName"><code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeName</span></code></a>. The value is a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.hasAttributes"> <code class="descclassname">Node.</code><code class="descname">hasAttributes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.hasAttributes" title="Permalink to this definition">¶</a></dt> <dd><p>Returns true if the node has any attributes.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.hasChildNodes"> <code class="descclassname">Node.</code><code class="descname">hasChildNodes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.hasChildNodes" title="Permalink to this definition">¶</a></dt> <dd><p>Returns true if the node has any child nodes.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.isSameNode"> <code class="descclassname">Node.</code><code class="descname">isSameNode</code><span class="sig-paren">(</span><em>other</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.isSameNode" title="Permalink to this definition">¶</a></dt> <dd><p>Returns true if <em>other</em> 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).</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">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).</p> </div> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.appendChild"> <code class="descclassname">Node.</code><code class="descname">appendChild</code><span class="sig-paren">(</span><em>newChild</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.appendChild" title="Permalink to this definition">¶</a></dt> <dd><p>Add a new child node to this node at the end of the list of children, returning <em>newChild</em>. If the node was already in the tree, it is removed first.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.insertBefore"> <code class="descclassname">Node.</code><code class="descname">insertBefore</code><span class="sig-paren">(</span><em>newChild</em>, <em>refChild</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.insertBefore" title="Permalink to this definition">¶</a></dt> <dd><p>Insert a new child node before an existing child. It must be the case that <em>refChild</em> is a child of this node; if not, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised. <em>newChild</em> is returned. If <em>refChild</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, it inserts <em>newChild</em> at the end of the children’s list.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.removeChild"> <code class="descclassname">Node.</code><code class="descname">removeChild</code><span class="sig-paren">(</span><em>oldChild</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.removeChild" title="Permalink to this definition">¶</a></dt> <dd><p>Remove a child node. <em>oldChild</em> must be a child of this node; if not, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised. <em>oldChild</em> is returned on success. If <em>oldChild</em> will not be used further, its <code class="xref py py-meth docutils literal notranslate"><span class="pre">unlink()</span></code> method should be called.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.replaceChild"> <code class="descclassname">Node.</code><code class="descname">replaceChild</code><span class="sig-paren">(</span><em>newChild</em>, <em>oldChild</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.replaceChild" title="Permalink to this definition">¶</a></dt> <dd><p>Replace an existing node with a new node. It must be the case that <em>oldChild</em> is a child of this node; if not, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.normalize"> <code class="descclassname">Node.</code><code class="descname">normalize</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.normalize" title="Permalink to this definition">¶</a></dt> <dd><p>Join adjacent text nodes so that all stretches of text are stored as single <code class="xref py py-class docutils literal notranslate"><span class="pre">Text</span></code> instances. This simplifies processing text from a DOM tree for many applications.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Node.cloneNode"> <code class="descclassname">Node.</code><code class="descname">cloneNode</code><span class="sig-paren">(</span><em>deep</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Node.cloneNode" title="Permalink to this definition">¶</a></dt> <dd><p>Clone this node. Setting <em>deep</em> means to clone all child nodes as well. This returns the clone.</p> </dd></dl> </div> <div class="section" id="nodelist-objects"> <span id="dom-nodelist-objects"></span><h3>20.6.2.3. NodeList Objects<a class="headerlink" href="#nodelist-objects" title="Permalink to this headline">¶</a></h3> <p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> represents a sequence of nodes. These objects are used in two ways in the DOM Core recommendation: an <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object provides one as its list of child nodes, and the <code class="xref py py-meth docutils literal notranslate"><span class="pre">getElementsByTagName()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">getElementsByTagNameNS()</span></code> methods of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> return objects with this interface to represent query results.</p> <p>The DOM Level 2 recommendation defines one method and one attribute for these objects:</p> <dl class="method"> <dt id="xml.dom.NodeList.item"> <code class="descclassname">NodeList.</code><code class="descname">item</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.NodeList.item" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <em>i</em>’th item from the sequence, if there is one, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. The index <em>i</em> is not allowed to be less than zero or greater than or equal to the length of the sequence.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.NodeList.length"> <code class="descclassname">NodeList.</code><code class="descname">length</code><a class="headerlink" href="#xml.dom.NodeList.length" title="Permalink to this definition">¶</a></dt> <dd><p>The number of nodes in the sequence.</p> </dd></dl> <p>In addition, the Python DOM interface requires that some additional support is provided to allow <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> objects to be used as Python sequences. All <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> implementations must include support for <a class="reference internal" href="../reference/datamodel.html#object.__len__" title="object.__len__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__len__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>; this allows iteration over the <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> in <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a> statements and proper support for the <a class="reference internal" href="functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> built-in function.</p> <p>If a DOM implementation supports modification of the document, the <code class="xref py py-class docutils literal notranslate"><span class="pre">NodeList</span></code> implementation must also support the <a class="reference internal" href="../reference/datamodel.html#object.__setitem__" title="object.__setitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setitem__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__delitem__" title="object.__delitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__delitem__()</span></code></a> methods.</p> </div> <div class="section" id="documenttype-objects"> <span id="dom-documenttype-objects"></span><h3>20.6.2.4. DocumentType Objects<a class="headerlink" href="#documenttype-objects" title="Permalink to this headline">¶</a></h3> <p>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 <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> object. The <code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> for a document is available from the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> object’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">doctype</span></code> attribute; if there is no <code class="docutils literal notranslate"><span class="pre">DOCTYPE</span></code> declaration for the document, the document’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">doctype</span></code> attribute will be set to <code class="docutils literal notranslate"><span class="pre">None</span></code> instead of an instance of this interface.</p> <p><code class="xref py py-class docutils literal notranslate"><span class="pre">DocumentType</span></code> is a specialization of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, and adds the following attributes:</p> <dl class="attribute"> <dt id="xml.dom.DocumentType.publicId"> <code class="descclassname">DocumentType.</code><code class="descname">publicId</code><a class="headerlink" href="#xml.dom.DocumentType.publicId" title="Permalink to this definition">¶</a></dt> <dd><p>The public identifier for the external subset of the document type definition. This will be a string or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.DocumentType.systemId"> <code class="descclassname">DocumentType.</code><code class="descname">systemId</code><a class="headerlink" href="#xml.dom.DocumentType.systemId" title="Permalink to this definition">¶</a></dt> <dd><p>The system identifier for the external subset of the document type definition. This will be a URI as a string, or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.DocumentType.internalSubset"> <code class="descclassname">DocumentType.</code><code class="descname">internalSubset</code><a class="headerlink" href="#xml.dom.DocumentType.internalSubset" title="Permalink to this definition">¶</a></dt> <dd><p>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 <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.DocumentType.name"> <code class="descclassname">DocumentType.</code><code class="descname">name</code><a class="headerlink" href="#xml.dom.DocumentType.name" title="Permalink to this definition">¶</a></dt> <dd><p>The name of the root element as given in the <code class="docutils literal notranslate"><span class="pre">DOCTYPE</span></code> declaration, if present.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.DocumentType.entities"> <code class="descclassname">DocumentType.</code><code class="descname">entities</code><a class="headerlink" href="#xml.dom.DocumentType.entities" title="Permalink to this definition">¶</a></dt> <dd><p>This is a <code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> 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 <code class="docutils literal notranslate"><span class="pre">None</span></code> if the information is not provided by the parser, or if no entities are defined.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.DocumentType.notations"> <code class="descclassname">DocumentType.</code><code class="descname">notations</code><a class="headerlink" href="#xml.dom.DocumentType.notations" title="Permalink to this definition">¶</a></dt> <dd><p>This is a <code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> 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 <code class="docutils literal notranslate"><span class="pre">None</span></code> if the information is not provided by the parser, or if no notations are defined.</p> </dd></dl> </div> <div class="section" id="document-objects"> <span id="dom-document-objects"></span><h3>20.6.2.5. Document Objects<a class="headerlink" href="#document-objects" title="Permalink to this headline">¶</a></h3> <p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> represents an entire XML document, including its constituent elements, attributes, processing instructions, comments etc. Remember that it inherits properties from <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>.</p> <dl class="attribute"> <dt id="xml.dom.Document.documentElement"> <code class="descclassname">Document.</code><code class="descname">documentElement</code><a class="headerlink" href="#xml.dom.Document.documentElement" title="Permalink to this definition">¶</a></dt> <dd><p>The one and only root element of the document.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createElement"> <code class="descclassname">Document.</code><code class="descname">createElement</code><span class="sig-paren">(</span><em>tagName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createElement" title="Permalink to this definition">¶</a></dt> <dd><p>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 <code class="xref py py-meth docutils literal notranslate"><span class="pre">insertBefore()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">appendChild()</span></code>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createElementNS"> <code class="descclassname">Document.</code><code class="descname">createElementNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>tagName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createElementNS" title="Permalink to this definition">¶</a></dt> <dd><p>Create and return a new element with a namespace. The <em>tagName</em> 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 <code class="xref py py-meth docutils literal notranslate"><span class="pre">insertBefore()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">appendChild()</span></code>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createTextNode"> <code class="descclassname">Document.</code><code class="descname">createTextNode</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createTextNode" title="Permalink to this definition">¶</a></dt> <dd><p>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.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createComment"> <code class="descclassname">Document.</code><code class="descname">createComment</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createComment" title="Permalink to this definition">¶</a></dt> <dd><p>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.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createProcessingInstruction"> <code class="descclassname">Document.</code><code class="descname">createProcessingInstruction</code><span class="sig-paren">(</span><em>target</em>, <em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createProcessingInstruction" title="Permalink to this definition">¶</a></dt> <dd><p>Create and return a processing instruction node containing the <em>target</em> and <em>data</em> passed as parameters. As with the other creation methods, this one does not insert the node into the tree.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createAttribute"> <code class="descclassname">Document.</code><code class="descname">createAttribute</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createAttribute" title="Permalink to this definition">¶</a></dt> <dd><p>Create and return an attribute node. This method does not associate the attribute node with any particular element. You must use <code class="xref py py-meth docutils literal notranslate"><span class="pre">setAttributeNode()</span></code> on the appropriate <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object to use the newly created attribute instance.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.createAttributeNS"> <code class="descclassname">Document.</code><code class="descname">createAttributeNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>qualifiedName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.createAttributeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Create and return an attribute node with a namespace. The <em>tagName</em> may have a prefix. This method does not associate the attribute node with any particular element. You must use <code class="xref py py-meth docutils literal notranslate"><span class="pre">setAttributeNode()</span></code> on the appropriate <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> object to use the newly created attribute instance.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.getElementsByTagName"> <code class="descclassname">Document.</code><code class="descname">getElementsByTagName</code><span class="sig-paren">(</span><em>tagName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.getElementsByTagName" title="Permalink to this definition">¶</a></dt> <dd><p>Search for all descendants (direct children, children’s children, etc.) with a particular element type name.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Document.getElementsByTagNameNS"> <code class="descclassname">Document.</code><code class="descname">getElementsByTagNameNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>localName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Document.getElementsByTagNameNS" title="Permalink to this definition">¶</a></dt> <dd><p>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.</p> </dd></dl> </div> <div class="section" id="element-objects"> <span id="dom-element-objects"></span><h3>20.6.2.6. Element Objects<a class="headerlink" href="#element-objects" title="Permalink to this headline">¶</a></h3> <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> is a subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, so inherits all the attributes of that class.</p> <dl class="attribute"> <dt id="xml.dom.Element.tagName"> <code class="descclassname">Element.</code><code class="descname">tagName</code><a class="headerlink" href="#xml.dom.Element.tagName" title="Permalink to this definition">¶</a></dt> <dd><p>The element type name. In a namespace-using document it may have colons in it. The value is a string.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.getElementsByTagName"> <code class="descclassname">Element.</code><code class="descname">getElementsByTagName</code><span class="sig-paren">(</span><em>tagName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getElementsByTagName" title="Permalink to this definition">¶</a></dt> <dd><p>Same as equivalent method in the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> class.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.getElementsByTagNameNS"> <code class="descclassname">Element.</code><code class="descname">getElementsByTagNameNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>localName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getElementsByTagNameNS" title="Permalink to this definition">¶</a></dt> <dd><p>Same as equivalent method in the <code class="xref py py-class docutils literal notranslate"><span class="pre">Document</span></code> class.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.hasAttribute"> <code class="descclassname">Element.</code><code class="descname">hasAttribute</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.hasAttribute" title="Permalink to this definition">¶</a></dt> <dd><p>Returns true if the element has an attribute named by <em>name</em>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.hasAttributeNS"> <code class="descclassname">Element.</code><code class="descname">hasAttributeNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>localName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.hasAttributeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Returns true if the element has an attribute named by <em>namespaceURI</em> and <em>localName</em>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.getAttribute"> <code class="descclassname">Element.</code><code class="descname">getAttribute</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttribute" title="Permalink to this definition">¶</a></dt> <dd><p>Return the value of the attribute named by <em>name</em> as a string. If no such attribute exists, an empty string is returned, as if the attribute had no value.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.getAttributeNode"> <code class="descclassname">Element.</code><code class="descname">getAttributeNode</code><span class="sig-paren">(</span><em>attrname</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttributeNode" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> node for the attribute named by <em>attrname</em>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.getAttributeNS"> <code class="descclassname">Element.</code><code class="descname">getAttributeNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>localName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttributeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Return the value of the attribute named by <em>namespaceURI</em> and <em>localName</em> as a string. If no such attribute exists, an empty string is returned, as if the attribute had no value.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.getAttributeNodeNS"> <code class="descclassname">Element.</code><code class="descname">getAttributeNodeNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>localName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.getAttributeNodeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Return an attribute value as a node, given a <em>namespaceURI</em> and <em>localName</em>.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.removeAttribute"> <code class="descclassname">Element.</code><code class="descname">removeAttribute</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.removeAttribute" title="Permalink to this definition">¶</a></dt> <dd><p>Remove an attribute by name. If there is no matching attribute, a <a class="reference internal" href="#xml.dom.NotFoundErr" title="xml.dom.NotFoundErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFoundErr</span></code></a> is raised.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.removeAttributeNode"> <code class="descclassname">Element.</code><code class="descname">removeAttributeNode</code><span class="sig-paren">(</span><em>oldAttr</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.removeAttributeNode" title="Permalink to this definition">¶</a></dt> <dd><p>Remove and return <em>oldAttr</em> from the attribute list, if present. If <em>oldAttr</em> is not present, <a class="reference internal" href="#xml.dom.NotFoundErr" title="xml.dom.NotFoundErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFoundErr</span></code></a> is raised.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.removeAttributeNS"> <code class="descclassname">Element.</code><code class="descname">removeAttributeNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>localName</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.removeAttributeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Remove an attribute by name. Note that it uses a localName, not a qname. No exception is raised if there is no matching attribute.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.setAttribute"> <code class="descclassname">Element.</code><code class="descname">setAttribute</code><span class="sig-paren">(</span><em>name</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttribute" title="Permalink to this definition">¶</a></dt> <dd><p>Set an attribute value from a string.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.setAttributeNode"> <code class="descclassname">Element.</code><code class="descname">setAttributeNode</code><span class="sig-paren">(</span><em>newAttr</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttributeNode" title="Permalink to this definition">¶</a></dt> <dd><p>Add a new attribute node to the element, replacing an existing attribute if necessary if the <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> attribute matches. If a replacement occurs, the old attribute node will be returned. If <em>newAttr</em> is already in use, <a class="reference internal" href="#xml.dom.InuseAttributeErr" title="xml.dom.InuseAttributeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InuseAttributeErr</span></code></a> will be raised.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.setAttributeNodeNS"> <code class="descclassname">Element.</code><code class="descname">setAttributeNodeNS</code><span class="sig-paren">(</span><em>newAttr</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttributeNodeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Add a new attribute node to the element, replacing an existing attribute if necessary if the <code class="xref py py-attr docutils literal notranslate"><span class="pre">namespaceURI</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">localName</span></code> attributes match. If a replacement occurs, the old attribute node will be returned. If <em>newAttr</em> is already in use, <a class="reference internal" href="#xml.dom.InuseAttributeErr" title="xml.dom.InuseAttributeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InuseAttributeErr</span></code></a> will be raised.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.Element.setAttributeNS"> <code class="descclassname">Element.</code><code class="descname">setAttributeNS</code><span class="sig-paren">(</span><em>namespaceURI</em>, <em>qname</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.Element.setAttributeNS" title="Permalink to this definition">¶</a></dt> <dd><p>Set an attribute value from a string, given a <em>namespaceURI</em> and a <em>qname</em>. Note that a qname is the whole attribute name. This is different than above.</p> </dd></dl> </div> <div class="section" id="attr-objects"> <span id="dom-attr-objects"></span><h3>20.6.2.7. Attr Objects<a class="headerlink" href="#attr-objects" title="Permalink to this headline">¶</a></h3> <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> inherits from <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, so inherits all its attributes.</p> <dl class="attribute"> <dt id="xml.dom.Attr.name"> <code class="descclassname">Attr.</code><code class="descname">name</code><a class="headerlink" href="#xml.dom.Attr.name" title="Permalink to this definition">¶</a></dt> <dd><p>The attribute name. In a namespace-using document it may include a colon.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Attr.localName"> <code class="descclassname">Attr.</code><code class="descname">localName</code><a class="headerlink" href="#xml.dom.Attr.localName" title="Permalink to this definition">¶</a></dt> <dd><p>The part of the name following the colon if there is one, else the entire name. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Attr.prefix"> <code class="descclassname">Attr.</code><code class="descname">prefix</code><a class="headerlink" href="#xml.dom.Attr.prefix" title="Permalink to this definition">¶</a></dt> <dd><p>The part of the name preceding the colon if there is one, else the empty string.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.Attr.value"> <code class="descclassname">Attr.</code><code class="descname">value</code><a class="headerlink" href="#xml.dom.Attr.value" title="Permalink to this definition">¶</a></dt> <dd><p>The text value of the attribute. This is a synonym for the <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeValue</span></code> attribute.</p> </dd></dl> </div> <div class="section" id="namednodemap-objects"> <span id="dom-attributelist-objects"></span><h3>20.6.2.8. NamedNodeMap Objects<a class="headerlink" href="#namednodemap-objects" title="Permalink to this headline">¶</a></h3> <p><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedNodeMap</span></code> does <em>not</em> inherit from <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>.</p> <dl class="attribute"> <dt id="xml.dom.NamedNodeMap.length"> <code class="descclassname">NamedNodeMap.</code><code class="descname">length</code><a class="headerlink" href="#xml.dom.NamedNodeMap.length" title="Permalink to this definition">¶</a></dt> <dd><p>The length of the attribute list.</p> </dd></dl> <dl class="method"> <dt id="xml.dom.NamedNodeMap.item"> <code class="descclassname">NamedNodeMap.</code><code class="descname">item</code><span class="sig-paren">(</span><em>index</em><span class="sig-paren">)</span><a class="headerlink" href="#xml.dom.NamedNodeMap.item" title="Permalink to this definition">¶</a></dt> <dd><p>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 <code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code> attribute.</p> </dd></dl> <p>There are also experimental methods that give this class more mapping behavior. You can use them or you can use the standardized <code class="xref py py-meth docutils literal notranslate"><span class="pre">getAttribute*()</span></code> family of methods on the <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> objects.</p> </div> <div class="section" id="comment-objects"> <span id="dom-comment-objects"></span><h3>20.6.2.9. Comment Objects<a class="headerlink" href="#comment-objects" title="Permalink to this headline">¶</a></h3> <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Comment</span></code> represents a comment in the XML document. It is a subclass of <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code>, but cannot have child nodes.</p> <dl class="attribute"> <dt id="xml.dom.Comment.data"> <code class="descclassname">Comment.</code><code class="descname">data</code><a class="headerlink" href="#xml.dom.Comment.data" title="Permalink to this definition">¶</a></dt> <dd><p>The content of the comment as a string. The attribute contains all characters between the leading <code class="docutils literal notranslate"><span class="pre"><!-</span></code><code class="docutils literal notranslate"><span class="pre">-</span></code> and trailing <code class="docutils literal notranslate"><span class="pre">-</span></code><code class="docutils literal notranslate"><span class="pre">-></span></code>, but does not include them.</p> </dd></dl> </div> <div class="section" id="text-and-cdatasection-objects"> <span id="dom-text-objects"></span><h3>20.6.2.10. Text and CDATASection Objects<a class="headerlink" href="#text-and-cdatasection-objects" title="Permalink to this headline">¶</a></h3> <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">Text</span></code> 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 <code class="xref py py-class docutils literal notranslate"><span class="pre">CDATASection</span></code> objects. These two interfaces are identical, but provide different values for the <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodeType</span></code> attribute.</p> <p>These interfaces extend the <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> interface. They cannot have child nodes.</p> <dl class="attribute"> <dt id="xml.dom.Text.data"> <code class="descclassname">Text.</code><code class="descname">data</code><a class="headerlink" href="#xml.dom.Text.data" title="Permalink to this definition">¶</a></dt> <dd><p>The content of the text node as a string.</p> </dd></dl> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The use of a <code class="xref py py-class docutils literal notranslate"><span class="pre">CDATASection</span></code> 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 <code class="xref py py-class docutils literal notranslate"><span class="pre">CDATASection</span></code> nodes represent different CDATA marked sections.</p> </div> </div> <div class="section" id="processinginstruction-objects"> <span id="dom-pi-objects"></span><h3>20.6.2.11. ProcessingInstruction Objects<a class="headerlink" href="#processinginstruction-objects" title="Permalink to this headline">¶</a></h3> <p>Represents a processing instruction in the XML document; this inherits from the <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> interface and cannot have child nodes.</p> <dl class="attribute"> <dt id="xml.dom.ProcessingInstruction.target"> <code class="descclassname">ProcessingInstruction.</code><code class="descname">target</code><a class="headerlink" href="#xml.dom.ProcessingInstruction.target" title="Permalink to this definition">¶</a></dt> <dd><p>The content of the processing instruction up to the first whitespace character. This is a read-only attribute.</p> </dd></dl> <dl class="attribute"> <dt id="xml.dom.ProcessingInstruction.data"> <code class="descclassname">ProcessingInstruction.</code><code class="descname">data</code><a class="headerlink" href="#xml.dom.ProcessingInstruction.data" title="Permalink to this definition">¶</a></dt> <dd><p>The content of the processing instruction following the first whitespace character.</p> </dd></dl> </div> <div class="section" id="exceptions"> <span id="dom-exceptions"></span><h3>20.6.2.12. Exceptions<a class="headerlink" href="#exceptions" title="Permalink to this headline">¶</a></h3> <p>The DOM Level 2 recommendation defines a single exception, <a class="reference internal" href="#xml.dom.DOMException" title="xml.dom.DOMException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DOMException</span></code></a>, and a number of constants that allow applications to determine what sort of error occurred. <a class="reference internal" href="#xml.dom.DOMException" title="xml.dom.DOMException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DOMException</span></code></a> instances carry a <a class="reference internal" href="code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-attr docutils literal notranslate"><span class="pre">code</span></code></a> attribute that provides the appropriate value for the specific exception.</p> <p>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 <a class="reference internal" href="code.html#module-code" title="code: Facilities to implement read-eval-print loops."><code class="xref py py-attr docutils literal notranslate"><span class="pre">code</span></code></a> attribute.</p> <dl class="exception"> <dt id="xml.dom.DOMException"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">DOMException</code><a class="headerlink" href="#xml.dom.DOMException" title="Permalink to this definition">¶</a></dt> <dd><p>Base exception class used for all specific DOM exceptions. This exception class cannot be directly instantiated.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.DomstringSizeErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">DomstringSizeErr</code><a class="headerlink" href="#xml.dom.DomstringSizeErr" title="Permalink to this definition">¶</a></dt> <dd><p>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.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.HierarchyRequestErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">HierarchyRequestErr</code><a class="headerlink" href="#xml.dom.HierarchyRequestErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when an attempt is made to insert a node where the node type is not allowed.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.IndexSizeErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">IndexSizeErr</code><a class="headerlink" href="#xml.dom.IndexSizeErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when an index or size parameter to a method is negative or exceeds the allowed values.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.InuseAttributeErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">InuseAttributeErr</code><a class="headerlink" href="#xml.dom.InuseAttributeErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when an attempt is made to insert an <code class="xref py py-class docutils literal notranslate"><span class="pre">Attr</span></code> node that is already present elsewhere in the document.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.InvalidAccessErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">InvalidAccessErr</code><a class="headerlink" href="#xml.dom.InvalidAccessErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised if a parameter or an operation is not supported on the underlying object.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.InvalidCharacterErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">InvalidCharacterErr</code><a class="headerlink" href="#xml.dom.InvalidCharacterErr" title="Permalink to this definition">¶</a></dt> <dd><p>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 <code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code> node with a space in the element type name will cause this error to be raised.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.InvalidModificationErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">InvalidModificationErr</code><a class="headerlink" href="#xml.dom.InvalidModificationErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when an attempt is made to modify the type of a node.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.InvalidStateErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">InvalidStateErr</code><a class="headerlink" href="#xml.dom.InvalidStateErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when an attempt is made to use an object that is not defined or is no longer usable.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.NamespaceErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">NamespaceErr</code><a class="headerlink" href="#xml.dom.NamespaceErr" title="Permalink to this definition">¶</a></dt> <dd><p>If an attempt is made to change any object in a way that is not permitted with regard to the <a class="reference external" href="https://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a> recommendation, this exception is raised.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.NotFoundErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">NotFoundErr</code><a class="headerlink" href="#xml.dom.NotFoundErr" title="Permalink to this definition">¶</a></dt> <dd><p>Exception when a node does not exist in the referenced context. For example, <code class="xref py py-meth docutils literal notranslate"><span class="pre">NamedNodeMap.removeNamedItem()</span></code> will raise this if the node passed in does not exist in the map.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.NotSupportedErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">NotSupportedErr</code><a class="headerlink" href="#xml.dom.NotSupportedErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when the implementation does not support the requested type of object or operation.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.NoDataAllowedErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">NoDataAllowedErr</code><a class="headerlink" href="#xml.dom.NoDataAllowedErr" title="Permalink to this definition">¶</a></dt> <dd><p>This is raised if data is specified for a node which does not support data.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.NoModificationAllowedErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">NoModificationAllowedErr</code><a class="headerlink" href="#xml.dom.NoModificationAllowedErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised on attempts to modify an object where modifications are not allowed (such as for read-only nodes).</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.SyntaxErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">SyntaxErr</code><a class="headerlink" href="#xml.dom.SyntaxErr" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when an invalid or illegal string is specified.</p> </dd></dl> <dl class="exception"> <dt id="xml.dom.WrongDocumentErr"> <em class="property">exception </em><code class="descclassname">xml.dom.</code><code class="descname">WrongDocumentErr</code><a class="headerlink" href="#xml.dom.WrongDocumentErr" title="Permalink to this definition">¶</a></dt> <dd><p>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.</p> </dd></dl> <p>The exception codes defined in the DOM recommendation map to the exceptions described above according to this table:</p> <table border="1" class="docutils"> <colgroup> <col width="54%" /> <col width="46%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Constant</th> <th class="head">Exception</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">DOMSTRING_SIZE_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.DomstringSizeErr" title="xml.dom.DomstringSizeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DomstringSizeErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">HIERARCHY_REQUEST_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.HierarchyRequestErr" title="xml.dom.HierarchyRequestErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">HierarchyRequestErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">INDEX_SIZE_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.IndexSizeErr" title="xml.dom.IndexSizeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexSizeErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">INUSE_ATTRIBUTE_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.InuseAttributeErr" title="xml.dom.InuseAttributeErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InuseAttributeErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_ACCESS_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.InvalidAccessErr" title="xml.dom.InvalidAccessErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidAccessErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_CHARACTER_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.InvalidCharacterErr" title="xml.dom.InvalidCharacterErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidCharacterErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_MODIFICATION_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.InvalidModificationErr" title="xml.dom.InvalidModificationErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidModificationErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">INVALID_STATE_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.InvalidStateErr" title="xml.dom.InvalidStateErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidStateErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">NAMESPACE_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.NamespaceErr" title="xml.dom.NamespaceErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NamespaceErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">NOT_FOUND_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.NotFoundErr" title="xml.dom.NotFoundErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFoundErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">NOT_SUPPORTED_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.NotSupportedErr" title="xml.dom.NotSupportedErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotSupportedErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">NO_DATA_ALLOWED_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.NoDataAllowedErr" title="xml.dom.NoDataAllowedErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoDataAllowedErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">NO_MODIFICATION_ALLOWED_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.NoModificationAllowedErr" title="xml.dom.NoModificationAllowedErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoModificationAllowedErr</span></code></a></td> </tr> <tr class="row-odd"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">SYNTAX_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.SyntaxErr" title="xml.dom.SyntaxErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxErr</span></code></a></td> </tr> <tr class="row-even"><td><code class="xref py py-const docutils literal notranslate"><span class="pre">WRONG_DOCUMENT_ERR</span></code></td> <td><a class="reference internal" href="#xml.dom.WrongDocumentErr" title="xml.dom.WrongDocumentErr"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WrongDocumentErr</span></code></a></td> </tr> </tbody> </table> </div> </div> <div class="section" id="conformance"> <span id="dom-conformance"></span><h2>20.6.3. Conformance<a class="headerlink" href="#conformance" title="Permalink to this headline">¶</a></h2> <p>This section describes the conformance requirements and relationships between the Python DOM API, the W3C DOM recommendations, and the OMG IDL mapping for Python.</p> <div class="section" id="type-mapping"> <span id="dom-type-mapping"></span><h3>20.6.3.1. Type Mapping<a class="headerlink" href="#type-mapping" title="Permalink to this headline">¶</a></h3> <p>The IDL types used in the DOM specification are mapped to Python types according to the following table.</p> <table border="1" class="docutils"> <colgroup> <col width="30%" /> <col width="70%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">IDL Type</th> <th class="head">Python Type</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">boolean</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">bool</span></code> or <code class="docutils literal notranslate"><span class="pre">int</span></code></td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">int</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">int</span></code></td> </tr> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">long</span> <span class="pre">int</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">int</span></code></td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">int</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">int</span></code></td> </tr> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">DOMString</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">str</span></code> or <code class="docutils literal notranslate"><span class="pre">bytes</span></code></td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">null</span></code></td> <td><code class="docutils literal notranslate"><span class="pre">None</span></code></td> </tr> </tbody> </table> </div> <div class="section" id="accessor-methods"> <span id="dom-accessor-methods"></span><h3>20.6.3.2. Accessor Methods<a class="headerlink" href="#accessor-methods" title="Permalink to this headline">¶</a></h3> <p>The mapping from OMG IDL to Python defines accessor functions for IDL <code class="docutils literal notranslate"><span class="pre">attribute</span></code> declarations in much the way the Java mapping does. Mapping the IDL declarations</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">readonly</span> <span class="n">attribute</span> <span class="n">string</span> <span class="n">someValue</span><span class="p">;</span> <span class="n">attribute</span> <span class="n">string</span> <span class="n">anotherValue</span><span class="p">;</span> </pre></div> </div> <p>yields three accessor functions: a “get” method for <code class="xref py py-attr docutils literal notranslate"><span class="pre">someValue</span></code> (<code class="xref py py-meth docutils literal notranslate"><span class="pre">_get_someValue()</span></code>), and “get” and “set” methods for <code class="xref py py-attr docutils literal notranslate"><span class="pre">anotherValue</span></code> (<code class="xref py py-meth docutils literal notranslate"><span class="pre">_get_anotherValue()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">_set_anotherValue()</span></code>). The mapping, in particular, does not require that the IDL attributes are accessible as normal Python attributes: <code class="docutils literal notranslate"><span class="pre">object.someValue</span></code> is <em>not</em> required to work, and may raise an <a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>.</p> <p>The Python DOM API, however, <em>does</em> 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 <code class="docutils literal notranslate"><span class="pre">readonly</span></code> may not restrict write access in all DOM implementations.</p> <p>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 <code class="docutils literal notranslate"><span class="pre">readonly</span></code> attributes.</p> <p>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 <code class="xref py py-meth docutils literal notranslate"><span class="pre">getElementsByTagName()</span></code>, being “live”. The Python DOM API does not require implementations to enforce such requirements.</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">20.6. <code class="docutils literal notranslate"><span class="pre">xml.dom</span></code> — The Document Object Model API</a><ul> <li><a class="reference internal" href="#module-contents">20.6.1. Module Contents</a></li> <li><a class="reference internal" href="#objects-in-the-dom">20.6.2. Objects in the DOM</a><ul> <li><a class="reference internal" href="#domimplementation-objects">20.6.2.1. DOMImplementation Objects</a></li> <li><a class="reference internal" href="#node-objects">20.6.2.2. Node Objects</a></li> <li><a class="reference internal" href="#nodelist-objects">20.6.2.3. NodeList Objects</a></li> <li><a class="reference internal" href="#documenttype-objects">20.6.2.4. DocumentType Objects</a></li> <li><a class="reference internal" href="#document-objects">20.6.2.5. Document Objects</a></li> <li><a class="reference internal" href="#element-objects">20.6.2.6. Element Objects</a></li> <li><a class="reference internal" href="#attr-objects">20.6.2.7. Attr Objects</a></li> <li><a class="reference internal" href="#namednodemap-objects">20.6.2.8. NamedNodeMap Objects</a></li> <li><a class="reference internal" href="#comment-objects">20.6.2.9. Comment Objects</a></li> <li><a class="reference internal" href="#text-and-cdatasection-objects">20.6.2.10. Text and CDATASection Objects</a></li> <li><a class="reference internal" href="#processinginstruction-objects">20.6.2.11. ProcessingInstruction Objects</a></li> <li><a class="reference internal" href="#exceptions">20.6.2.12. Exceptions</a></li> </ul> </li> <li><a class="reference internal" href="#conformance">20.6.3. Conformance</a><ul> <li><a class="reference internal" href="#type-mapping">20.6.3.1. Type Mapping</a></li> <li><a class="reference internal" href="#accessor-methods">20.6.3.2. Accessor Methods</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="xml.etree.elementtree.html" title="previous chapter">20.5. <code class="docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code> — The ElementTree XML API</a></p> <h4>Next topic</h4> <p class="topless"><a href="xml.dom.minidom.html" title="next chapter">20.7. <code class="docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code> — Minimal DOM implementation</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.6/Doc/library/xml.dom.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="xml.dom.minidom.html" title="20.7. xml.dom.minidom — Minimal DOM implementation" >next</a> |</li> <li class="right" > <a href="xml.etree.elementtree.html" title="20.5. xml.etree.ElementTree — The ElementTree XML API" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="markup.html" >20. Structured Markup Processing Tools</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Save
cmd:
run