/
usr
/
share
/
doc
/
python3-docs
/
html
/
_sources
/
library
/
/usr/share/doc/python3-docs/html/_sources/library
mkdir
upload
Name
Size
Mode
Actions
2to3.rst.txt
15898
0644
edit
dl
rm
abc.rst.txt
11805
0644
edit
dl
rm
aifc.rst.txt
7503
0644
edit
dl
rm
allos.rst.txt
678
0644
edit
dl
rm
archiving.rst.txt
440
0644
edit
dl
rm
argparse.rst.txt
77480
0644
edit
dl
rm
array.rst.txt
10812
0644
edit
dl
rm
ast.rst.txt
10159
0644
edit
dl
rm
asynchat.rst.txt
8528
0644
edit
dl
rm
asyncio-dev.rst.txt
13398
0644
edit
dl
rm
asyncio-eventloop.rst.txt
33701
0644
edit
dl
rm
asyncio-eventloops.rst.txt
7660
0644
edit
dl
rm
asyncio-protocol.rst.txt
25170
0644
edit
dl
rm
asyncio-queue.rst.txt
4328
0644
edit
dl
rm
asyncio-stream.rst.txt
14363
0644
edit
dl
rm
asyncio-subprocess.rst.txt
15544
0644
edit
dl
rm
asyncio-sync.rst.txt
9078
0644
edit
dl
rm
asyncio-task.rst.txt
25406
0644
edit
dl
rm
asyncio.rst.txt
2272
0644
edit
dl
rm
asyncore.rst.txt
13624
0644
edit
dl
rm
atexit.rst.txt
3669
0644
edit
dl
rm
audioop.rst.txt
10712
0644
edit
dl
rm
base64.rst.txt
10371
0644
edit
dl
rm
bdb.rst.txt
12985
0644
edit
dl
rm
binary.rst.txt
654
0644
edit
dl
rm
binascii.rst.txt
6539
0644
edit
dl
rm
binhex.rst.txt
1709
0644
edit
dl
rm
bisect.rst.txt
5398
0644
edit
dl
rm
builtins.rst.txt
1465
0644
edit
dl
rm
bz2.rst.txt
8825
0644
edit
dl
rm
calendar.rst.txt
10988
0644
edit
dl
rm
cgi.rst.txt
22650
0644
edit
dl
rm
cgitb.rst.txt
2918
0644
edit
dl
rm
chunk.rst.txt
5094
0644
edit
dl
rm
cmath.rst.txt
9326
0644
edit
dl
rm
cmd.rst.txt
13795
0644
edit
dl
rm
code.rst.txt
7817
0644
edit
dl
rm
codecs.rst.txt
75564
0644
edit
dl
rm
codeop.rst.txt
3021
0644
edit
dl
rm
collections.abc.rst.txt
12861
0644
edit
dl
rm
collections.rst.txt
46063
0644
edit
dl
rm
colorsys.rst.txt
1820
0644
edit
dl
rm
compileall.rst.txt
8975
0644
edit
dl
rm
concurrency.rst.txt
673
0644
edit
dl
rm
concurrent.futures.rst.txt
16910
0644
edit
dl
rm
concurrent.rst.txt
171
0644
edit
dl
rm
configparser.rst.txt
48756
0644
edit
dl
rm
constants.rst.txt
3331
0644
edit
dl
rm
contextlib.rst.txt
28175
0644
edit
dl
rm
copy.rst.txt
3378
0644
edit
dl
rm
copyreg.rst.txt
2182
0644
edit
dl
rm
crypt.rst.txt
5122
0644
edit
dl
rm
crypto.rst.txt
411
0644
edit
dl
rm
csv.rst.txt
19902
0644
edit
dl
rm
ctypes.rst.txt
88613
0644
edit
dl
rm
curses.ascii.rst.txt
8920
0644
edit
dl
rm
curses.panel.rst.txt
2764
0644
edit
dl
rm
curses.rst.txt
76397
0644
edit
dl
rm
custominterp.rst.txt
569
0644
edit
dl
rm
datatypes.rst.txt
751
0644
edit
dl
rm
datetime.rst.txt
90524
0644
edit
dl
rm
dbm.rst.txt
14293
0644
edit
dl
rm
debug.rst.txt
471
0644
edit
dl
rm
decimal.rst.txt
74869
0644
edit
dl
rm
development.rst.txt
704
0644
edit
dl
rm
difflib.rst.txt
29861
0644
edit
dl
rm
dis.rst.txt
32567
0644
edit
dl
rm
distribution.rst.txt
452
0644
edit
dl
rm
distutils.rst.txt
1974
0644
edit
dl
rm
doctest.rst.txt
71743
0644
edit
dl
rm
dummy_threading.rst.txt
784
0644
edit
dl
rm
email.charset.rst.txt
9293
0644
edit
dl
rm
email.compat32-message.rst.txt
33493
0644
edit
dl
rm
email.contentmanager.rst.txt
9112
0644
edit
dl
rm
email.encoders.rst.txt
2715
0644
edit
dl
rm
email.errors.rst.txt
4792
0644
edit
dl
rm
email.examples.rst.txt
1915
0644
edit
dl
rm
email.generator.rst.txt
13637
0644
edit
dl
rm
email.header.rst.txt
9188
0644
edit
dl
rm
email.headerregistry.rst.txt
17957
0644
edit
dl
rm
email.iterators.rst.txt
2795
0644
edit
dl
rm
email.message.rst.txt
33008
0644
edit
dl
rm
email.mime.rst.txt
11721
0644
edit
dl
rm
email.parser.rst.txt
14092
0644
edit
dl
rm
email.policy.rst.txt
27022
0644
edit
dl
rm
email.rst.txt
6785
0644
edit
dl
rm
email.util.rst.txt
9214
0644
edit
dl
rm
ensurepip.rst.txt
4987
0644
edit
dl
rm
enum.rst.txt
32751
0644
edit
dl
rm
errno.rst.txt
6811
0644
edit
dl
rm
exceptions.rst.txt
25570
0644
edit
dl
rm
faulthandler.rst.txt
6136
0644
edit
dl
rm
fcntl.rst.txt
7152
0644
edit
dl
rm
filecmp.rst.txt
5623
0644
edit
dl
rm
fileformats.rst.txt
287
0644
edit
dl
rm
fileinput.rst.txt
8051
0644
edit
dl
rm
filesys.rst.txt
961
0644
edit
dl
rm
fnmatch.rst.txt
3103
0644
edit
dl
rm
formatter.rst.txt
13242
0644
edit
dl
rm
fpectl.rst.txt
4180
0644
edit
dl
rm
fractions.rst.txt
6364
0644
edit
dl
rm
frameworks.rst.txt
391
0644
edit
dl
rm
ftplib.rst.txt
17552
0644
edit
dl
rm
functional.rst.txt
365
0644
edit
dl
rm
functions.rst.txt
71621
0644
edit
dl
rm
functools.rst.txt
18503
0644
edit
dl
rm
gc.rst.txt
9694
0644
edit
dl
rm
getopt.rst.txt
6557
0644
edit
dl
rm
getpass.rst.txt
1882
0644
edit
dl
rm
gettext.rst.txt
25588
0644
edit
dl
rm
glob.rst.txt
3508
0644
edit
dl
rm
grp.rst.txt
2417
0644
edit
dl
rm
gzip.rst.txt
8301
0644
edit
dl
rm
hashlib.rst.txt
26523
0644
edit
dl
rm
heapq.rst.txt
13402
0644
edit
dl
rm
hmac.rst.txt
4020
0644
edit
dl
rm
html.entities.rst.txt
1319
0644
edit
dl
rm
html.parser.rst.txt
11275
0644
edit
dl
rm
html.rst.txt
1304
0644
edit
dl
rm
http.client.rst.txt
18870
0644
edit
dl
rm
http.cookiejar.rst.txt
27832
0644
edit
dl
rm
http.cookies.rst.txt
8645
0644
edit
dl
rm
http.rst.txt
7096
0644
edit
dl
rm
http.server.rst.txt
17639
0644
edit
dl
rm
i18n.rst.txt
408
0644
edit
dl
rm
idle.rst.txt
25834
0644
edit
dl
rm
imaplib.rst.txt
20367
0644
edit
dl
rm
imghdr.rst.txt
2938
0644
edit
dl
rm
imp.rst.txt
15548
0644
edit
dl
rm
importlib.rst.txt
53563
0644
edit
dl
rm
index.rst.txt
2258
0644
edit
dl
rm
inspect.rst.txt
53928
0644
edit
dl
rm
internet.rst.txt
992
0644
edit
dl
rm
intro.rst.txt
2645
0644
edit
dl
rm
io.rst.txt
40328
0644
edit
dl
rm
ipaddress.rst.txt
32340
0644
edit
dl
rm
ipc.rst.txt
649
0644
edit
dl
rm
itertools.rst.txt
38459
0644
edit
dl
rm
json.rst.txt
27876
0644
edit
dl
rm
keyword.rst.txt
617
0644
edit
dl
rm
language.rst.txt
522
0644
edit
dl
rm
linecache.rst.txt
2408
0644
edit
dl
rm
locale.rst.txt
25470
0644
edit
dl
rm
logging.config.rst.txt
33886
0644
edit
dl
rm
logging.handlers.rst.txt
42497
0644
edit
dl
rm
logging.rst.txt
60479
0644
edit
dl
rm
lzma.rst.txt
17361
0644
edit
dl
rm
macpath.rst.txt
707
0644
edit
dl
rm
mailbox.rst.txt
63055
0644
edit
dl
rm
mailcap.rst.txt
3691
0644
edit
dl
rm
markup.rst.txt
679
0644
edit
dl
rm
marshal.rst.txt
4855
0644
edit
dl
rm
math.rst.txt
14375
0644
edit
dl
rm
mimetypes.rst.txt
9839
0644
edit
dl
rm
misc.rst.txt
247
0644
edit
dl
rm
mm.rst.txt
431
0644
edit
dl
rm
mmap.rst.txt
11232
0644
edit
dl
rm
modulefinder.rst.txt
3240
0644
edit
dl
rm
modules.rst.txt
355
0644
edit
dl
rm
msilib.rst.txt
18612
0644
edit
dl
rm
msvcrt.rst.txt
4392
0644
edit
dl
rm
multiprocessing.rst.txt
104494
0644
edit
dl
rm
netdata.rst.txt
339
0644
edit
dl
rm
netrc.rst.txt
3007
0644
edit
dl
rm
nis.rst.txt
1993
0644
edit
dl
rm
nntplib.rst.txt
21821
0644
edit
dl
rm
numbers.rst.txt
8089
0644
edit
dl
rm
numeric.rst.txt
696
0644
edit
dl
rm
operator.rst.txt
18989
0644
edit
dl
rm
optparse.rst.txt
76996
0644
edit
dl
rm
os.path.rst.txt
16419
0644
edit
dl
rm
os.rst.txt
137534
0644
edit
dl
rm
ossaudiodev.rst.txt
17845
0644
edit
dl
rm
othergui.rst.txt
2822
0644
edit
dl
rm
parser.rst.txt
15148
0644
edit
dl
rm
pathlib.rst.txt
30045
0644
edit
dl
rm
pdb.rst.txt
19454
0644
edit
dl
rm
persistence.rst.txt
591
0644
edit
dl
rm
pickle.rst.txt
37440
0644
edit
dl
rm
pickletools.rst.txt
3729
0644
edit
dl
rm
pipes.rst.txt
2557
0644
edit
dl
rm
pkgutil.rst.txt
8730
0644
edit
dl
rm
platform.rst.txt
9624
0644
edit
dl
rm
plistlib.rst.txt
7398
0644
edit
dl
rm
poplib.rst.txt
8197
0644
edit
dl
rm
posix.rst.txt
3694
0644
edit
dl
rm
pprint.rst.txt
14274
0644
edit
dl
rm
profile.rst.txt
27969
0644
edit
dl
rm
pty.rst.txt
3123
0644
edit
dl
rm
pwd.rst.txt
2739
0644
edit
dl
rm
pyclbr.rst.txt
3297
0644
edit
dl
rm
pydoc.rst.txt
4688
0644
edit
dl
rm
pyexpat.rst.txt
28620
0644
edit
dl
rm
python.rst.txt
475
0644
edit
dl
rm
py_compile.rst.txt
3851
0644
edit
dl
rm
queue.rst.txt
7268
0644
edit
dl
rm
quopri.rst.txt
2571
0644
edit
dl
rm
random.rst.txt
18503
0644
edit
dl
rm
re.rst.txt
64936
0644
edit
dl
rm
readline.rst.txt
11943
0644
edit
dl
rm
reprlib.rst.txt
5162
0644
edit
dl
rm
resource.rst.txt
12291
0644
edit
dl
rm
rlcompleter.rst.txt
2294
0644
edit
dl
rm
runpy.rst.txt
8285
0644
edit
dl
rm
sched.rst.txt
4842
0644
edit
dl
rm
secrets.rst.txt
5930
0644
edit
dl
rm
select.rst.txt
28175
0644
edit
dl
rm
selectors.rst.txt
8925
0644
edit
dl
rm
shelve.rst.txt
8390
0644
edit
dl
rm
shlex.rst.txt
16441
0644
edit
dl
rm
shutil.rst.txt
26014
0644
edit
dl
rm
signal.rst.txt
17218
0644
edit
dl
rm
site.rst.txt
9628
0644
edit
dl
rm
smtpd.rst.txt
10806
0644
edit
dl
rm
smtplib.rst.txt
23439
0644
edit
dl
rm
sndhdr.rst.txt
1994
0644
edit
dl
rm
socket.rst.txt
68202
0644
edit
dl
rm
socketserver.rst.txt
23712
0644
edit
dl
rm
spwd.rst.txt
2958
0644
edit
dl
rm
sqlite3.rst.txt
39215
0644
edit
dl
rm
ssl.rst.txt
96021
0644
edit
dl
rm
stat.rst.txt
9805
0644
edit
dl
rm
statistics.rst.txt
15301
0644
edit
dl
rm
stdtypes.rst.txt
179240
0644
edit
dl
rm
string.rst.txt
35374
0644
edit
dl
rm
stringprep.rst.txt
4279
0644
edit
dl
rm
struct.rst.txt
19581
0644
edit
dl
rm
subprocess.rst.txt
45793
0644
edit
dl
rm
sunau.rst.txt
7390
0644
edit
dl
rm
superseded.rst.txt
258
0644
edit
dl
rm
symbol.rst.txt
975
0644
edit
dl
rm
symtable.rst.txt
4964
0644
edit
dl
rm
sys.rst.txt
58273
0644
edit
dl
rm
sysconfig.rst.txt
8749
0644
edit
dl
rm
syslog.rst.txt
4302
0644
edit
dl
rm
tabnanny.rst.txt
2007
0644
edit
dl
rm
tarfile.rst.txt
31749
0644
edit
dl
rm
telnetlib.rst.txt
7899
0644
edit
dl
rm
tempfile.rst.txt
13857
0644
edit
dl
rm
termios.rst.txt
3751
0644
edit
dl
rm
test.rst.txt
25764
0644
edit
dl
rm
text.rst.txt
584
0644
edit
dl
rm
textwrap.rst.txt
10519
0644
edit
dl
rm
threading.rst.txt
39257
0644
edit
dl
rm
time.rst.txt
32967
0644
edit
dl
rm
timeit.rst.txt
13000
0644
edit
dl
rm
tk.rst.txt
1639
0644
edit
dl
rm
tkinter.rst.txt
33027
0644
edit
dl
rm
tkinter.scrolledtext.rst.txt
1255
0644
edit
dl
rm
tkinter.tix.rst.txt
22653
0644
edit
dl
rm
tkinter.ttk.rst.txt
58489
0644
edit
dl
rm
token.rst.txt
2607
0644
edit
dl
rm
tokenize.rst.txt
10002
0644
edit
dl
rm
trace.rst.txt
6914
0644
edit
dl
rm
traceback.rst.txt
17854
0644
edit
dl
rm
tracemalloc.rst.txt
22089
0644
edit
dl
rm
tty.rst.txt
1097
0644
edit
dl
rm
turtle.rst.txt
71221
0644
edit
dl
rm
types.rst.txt
9999
0644
edit
dl
rm
typing.rst.txt
34332
0644
edit
dl
rm
undoc.rst.txt
780
0644
edit
dl
rm
unicodedata.rst.txt
5762
0644
edit
dl
rm
unittest.mock-examples.rst.txt
46206
0644
edit
dl
rm
unittest.mock.rst.txt
85991
0644
edit
dl
rm
unittest.rst.txt
93304
0644
edit
dl
rm
unix.rst.txt
446
0644
edit
dl
rm
urllib.error.rst.txt
2199
0644
edit
dl
rm
urllib.parse.rst.txt
27332
0644
edit
dl
rm
urllib.request.rst.txt
59360
0644
edit
dl
rm
urllib.robotparser.rst.txt
2969
0644
edit
dl
rm
urllib.rst.txt
466
0644
edit
dl
rm
uu.rst.txt
2387
0644
edit
dl
rm
uuid.rst.txt
8760
0644
edit
dl
rm
venv.rst.txt
20621
0644
edit
dl
rm
warnings.rst.txt
20152
0644
edit
dl
rm
wave.rst.txt
6870
0644
edit
dl
rm
weakref.rst.txt
21328
0644
edit
dl
rm
webbrowser.rst.txt
9783
0644
edit
dl
rm
windows.rst.txt
272
0644
edit
dl
rm
winreg.rst.txt
24073
0644
edit
dl
rm
winsound.rst.txt
5134
0644
edit
dl
rm
wsgiref.rst.txt
33047
0644
edit
dl
rm
xdrlib.rst.txt
8078
0644
edit
dl
rm
xml.dom.minidom.rst.txt
10198
0644
edit
dl
rm
xml.dom.pulldom.rst.txt
5186
0644
edit
dl
rm
xml.dom.rst.txt
39507
0644
edit
dl
rm
xml.etree.elementtree.rst.txt
43871
0644
edit
dl
rm
xml.rst.txt
6071
0644
edit
dl
rm
xml.sax.handler.rst.txt
15399
0644
edit
dl
rm
xml.sax.reader.rst.txt
12133
0644
edit
dl
rm
xml.sax.rst.txt
7159
0644
edit
dl
rm
xml.sax.utils.rst.txt
3901
0644
edit
dl
rm
xmlrpc.client.rst.txt
23071
0644
edit
dl
rm
xmlrpc.rst.txt
475
0644
edit
dl
rm
xmlrpc.server.rst.txt
14990
0644
edit
dl
rm
zipapp.rst.txt
17392
0644
edit
dl
rm
zipfile.rst.txt
24005
0644
edit
dl
rm
zipimport.rst.txt
5805
0644
edit
dl
rm
zlib.rst.txt
13912
0644
edit
dl
rm
_dummy_thread.rst.txt
762
0644
edit
dl
rm
_thread.rst.txt
6886
0644
edit
dl
rm
__future__.rst.txt
5245
0644
edit
dl
rm
__main__.rst.txt
904
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-docs/html/_sources/library/xml.dom.minidom.rst.txt
(10198B)
:mod:`xml.dom.minidom` --- Minimal DOM implementation ===================================================== .. module:: xml.dom.minidom :synopsis: Minimal Document Object Model (DOM) implementation. .. moduleauthor:: Paul Prescod <paul@prescod.net> .. sectionauthor:: Paul Prescod <paul@prescod.net> .. sectionauthor:: Martin v. Löwis <martin@v.loewis.de> **Source code:** :source:`Lib/xml/dom/minidom.py` -------------- :mod:`xml.dom.minidom` is a minimal implementation of the Document Object Model interface, with an API similar to that in other languages. It is intended to be simpler than the full DOM and also significantly smaller. Users who are not already proficient with the DOM should consider using the :mod:`xml.etree.ElementTree` module for their XML processing instead. .. warning:: The :mod:`xml.dom.minidom` module is not secure against maliciously constructed data. If you need to parse untrusted or unauthenticated data see :ref:`xml-vulnerabilities`. DOM applications typically start by parsing some XML into a DOM. With :mod:`xml.dom.minidom`, this is done through the parse functions:: from xml.dom.minidom import parse, parseString dom1 = parse('c:\\temp\\mydata.xml') # parse an XML file by name datasource = open('c:\\temp\\mydata.xml') dom2 = parse(datasource) # parse an open file dom3 = parseString('<myxml>Some data<empty/> some more data</myxml>') The :func:`parse` function can take either a filename or an open file object. .. function:: parse(filename_or_file, parser=None, bufsize=None) Return a :class:`Document` from the given input. *filename_or_file* may be either a file name, or a file-like object. *parser*, if given, must be a SAX2 parser object. This function will change the document handler of the parser and activate namespace support; other parser configuration (like setting an entity resolver) must have been done in advance. If you have XML in a string, you can use the :func:`parseString` function instead: .. function:: parseString(string, parser=None) Return a :class:`Document` that represents the *string*. This method creates an :class:`io.StringIO` object for the string and passes that on to :func:`parse`. Both functions return a :class:`Document` object representing the content of the document. What the :func:`parse` and :func:`parseString` functions do is connect an XML parser with a "DOM builder" that can accept parse events from any SAX parser and convert them into a DOM tree. The name of the functions are perhaps misleading, but are easy to grasp when learning the interfaces. The parsing of the document will be completed before these functions return; it's simply that these functions do not provide a parser implementation themselves. You can also create a :class:`Document` by calling a method on a "DOM Implementation" object. You can get this object either by calling the :func:`getDOMImplementation` function in the :mod:`xml.dom` package or the :mod:`xml.dom.minidom` module. Once you have a :class:`Document`, you can add child nodes to it to populate the DOM:: from xml.dom.minidom import getDOMImplementation impl = getDOMImplementation() newdoc = impl.createDocument(None, "some_tag", None) top_element = newdoc.documentElement text = newdoc.createTextNode('Some textual content.') top_element.appendChild(text) 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. The main property of the document object is the :attr:`documentElement` property. It gives you the main element in the XML document: the one that holds all others. Here is an example program:: dom3 = parseString("<myxml>Some data</myxml>") assert dom3.documentElement.tagName == "myxml" When you are finished with a DOM tree, you may optionally call the :meth:`unlink` method to encourage early cleanup of the now-unneeded objects. :meth:`unlink` is an :mod:`xml.dom.minidom`\ -specific extension to the DOM API that renders the node and its descendants are essentially useless. Otherwise, Python's garbage collector will eventually take care of the objects in the tree. .. seealso:: `Document Object Model (DOM) Level 1 Specification <https://www.w3.org/TR/REC-DOM-Level-1/>`_ The W3C recommendation for the DOM supported by :mod:`xml.dom.minidom`. .. _minidom-objects: DOM Objects ----------- The definition of the DOM API for Python is given as part of the :mod:`xml.dom` module documentation. This section lists the differences between the API and :mod:`xml.dom.minidom`. .. method:: Node.unlink() Break internal references within the DOM so that it will be garbage collected on versions of Python without cyclic GC. Even when cyclic GC is available, using this can make large amounts of memory available sooner, so calling this on DOM objects as soon as they are no longer needed is good practice. This only needs to be called on the :class:`Document` object, but may be called on child nodes to discard children of that node. You can avoid calling this method explicitly by using the :keyword:`with` statement. The following code will automatically unlink *dom* when the :keyword:`with` block is exited:: with xml.dom.minidom.parse(datasource) as dom: ... # Work with dom. .. method:: Node.writexml(writer, indent="", addindent="", newl="") Write XML to the writer object. The writer should have a :meth:`write` method which matches that of the file object interface. The *indent* parameter is the indentation of the current node. The *addindent* parameter is the incremental indentation to use for subnodes of the current one. The *newl* parameter specifies the string to use to terminate newlines. For the :class:`Document` node, an additional keyword argument *encoding* can be used to specify the encoding field of the XML header. .. method:: Node.toxml(encoding=None) Return a string or byte string containing the XML represented by the DOM node. With an explicit *encoding* [1]_ argument, the result is a byte string in the specified encoding. With no *encoding* argument, the result is a Unicode string, and the XML declaration in the resulting string does not specify an encoding. Encoding this string in an encoding other than UTF-8 is likely incorrect, since UTF-8 is the default encoding of XML. .. method:: Node.toprettyxml(indent="", newl="", encoding="") Return a pretty-printed version of the document. *indent* specifies the indentation string and defaults to a tabulator; *newl* specifies the string emitted at the end of each line and defaults to ``\n``. The *encoding* argument behaves like the corresponding argument of :meth:`toxml`. .. _dom-example: DOM Example ----------- This example program is a fairly realistic example of a simple program. In this particular case, we do not take much advantage of the flexibility of the DOM. .. literalinclude:: ../includes/minidom-example.py .. _minidom-and-dom: minidom and the DOM standard ---------------------------- The :mod:`xml.dom.minidom` module is essentially a DOM 1.0-compatible DOM with some DOM 2 features (primarily namespace features). Usage of the DOM interface in Python is straight-forward. The following mapping rules apply: * Interfaces are accessed through instance objects. Applications should not instantiate the classes themselves; they should use the creator functions available on the :class:`Document` object. Derived interfaces support all operations (and attributes) from the base interfaces, plus any new operations. * Operations are used as methods. Since the DOM uses only :keyword:`in` parameters, the arguments are passed in normal order (from left to right). There are no optional arguments. ``void`` operations return ``None``. * IDL attributes map to instance attributes. For compatibility with the OMG IDL language mapping for Python, an attribute ``foo`` can also be accessed through accessor methods :meth:`_get_foo` and :meth:`_set_foo`. ``readonly`` attributes must not be changed; this is not enforced at runtime. * The types ``short int``, ``unsigned int``, ``unsigned long long``, and ``boolean`` all map to Python integer objects. * The type ``DOMString`` maps to Python strings. :mod:`xml.dom.minidom` supports either bytes or strings, but will normally produce strings. Values of type ``DOMString`` may also be ``None`` where allowed to have the IDL ``null`` value by the DOM specification from the W3C. * ``const`` declarations map to variables in their respective scope (e.g. ``xml.dom.minidom.Node.PROCESSING_INSTRUCTION_NODE``); they must not be changed. * ``DOMException`` is currently not supported in :mod:`xml.dom.minidom`. Instead, :mod:`xml.dom.minidom` uses standard Python exceptions such as :exc:`TypeError` and :exc:`AttributeError`. * :class:`NodeList` objects are implemented using Python's built-in list type. These objects provide the interface defined in the DOM specification, but with earlier versions of Python they do not support the official API. They are, however, much more "Pythonic" than the interface defined in the W3C recommendations. The following interfaces have no implementation in :mod:`xml.dom.minidom`: * :class:`DOMTimeStamp` * :class:`DocumentType` * :class:`DOMImplementation` * :class:`CharacterData` * :class:`CDATASection` * :class:`Notation` * :class:`Entity` * :class:`EntityReference` * :class:`DocumentFragment` Most of these reflect information in the XML document that is not of general utility to most DOM users. .. rubric:: Footnotes .. [1] The encoding name included in the XML output should conform to the appropriate standards. For example, "UTF-8" is valid, but "UTF8" is not valid in an XML document's declaration, even though Python accepts it as an encoding name. See https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EncodingDecl and https://www.iana.org/assignments/character-sets/character-sets.xhtml.
Save
cmd:
run