Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5598cc90
Commit
5598cc90
authored
Nov 07, 2018
by
Diego Rojas
Committed by
Serhiy Storchaka
Nov 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34160: Preserve order of attributes in minidom. (GH-10219)
parent
f1944799
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
3 deletions
+34
-3
Doc/library/xml.dom.minidom.rst
Doc/library/xml.dom.minidom.rst
+11
-0
Lib/test/test_minidom.py
Lib/test/test_minidom.py
+21
-0
Lib/xml/dom/minidom.py
Lib/xml/dom/minidom.py
+1
-2
Misc/NEWS.d/next/Library/2018-10-27-21-11-42.bpo-34160.UzyPZf.rst
...S.d/next/Library/2018-10-27-21-11-42.bpo-34160.UzyPZf.rst
+1
-1
No files found.
Doc/library/xml.dom.minidom.rst
View file @
5598cc90
...
...
@@ -143,6 +143,9 @@ module documentation. This section lists the differences between the API and
For the :class:`Document` node, an additional keyword argument *encoding* can
be used to specify the encoding field of the XML header.
.. versionchanged:: 3.8
The :meth:`writexml` method now preserves the attribute order specified
by the user.
.. method:: Node.toxml(encoding=None)
...
...
@@ -156,6 +159,10 @@ module documentation. This section lists the differences between the API and
encoding. Encoding this string in an encoding other than UTF-8 is
likely incorrect, since UTF-8 is the default encoding of XML.
.. versionchanged:: 3.8
The :meth:`toxml` method now preserves the attribute order specified
by the user.
.. method:: Node.toprettyxml(indent="", newl="", encoding="")
Return a pretty-printed version of the document. *indent* specifies the
...
...
@@ -165,6 +172,10 @@ module documentation. This section lists the differences between the API and
The *encoding* argument behaves like the corresponding argument of
:meth:`toxml`.
.. versionchanged:: 3.8
The :meth:`toprettyxml` method now preserves the attribute order specified
by the user.
.. _dom-example:
...
...
Lib/test/test_minidom.py
View file @
5598cc90
...
...
@@ -2,6 +2,8 @@
import
copy
import
pickle
import
io
import
contextlib
from
test.support
import
findfile
import
unittest
...
...
@@ -1560,5 +1562,24 @@ class MinidomTest(unittest.TestCase):
pi
=
doc
.
createProcessingInstruction
(
"y"
,
"z"
)
pi
.
nodeValue
=
"crash"
def
test_minidom_attribute_order
(
self
):
xml_str
=
'<?xml version="1.0" ?><curriculum status="public" company="example"/>'
doc
=
parseString
(
xml_str
)
output
=
io
.
StringIO
()
doc
.
writexml
(
output
)
self
.
assertEqual
(
output
.
getvalue
(),
xml_str
)
def
test_toxml_with_attributes_ordered
(
self
):
xml_str
=
'<?xml version="1.0" ?><curriculum status="public" company="example"/>'
doc
=
parseString
(
xml_str
)
self
.
assertEqual
(
doc
.
toxml
(),
xml_str
)
def
test_toprettyxml_with_attributes_ordered
(
self
):
xml_str
=
'<?xml version="1.0" ?><curriculum status="public" company="example"/>'
doc
=
parseString
(
xml_str
)
self
.
assertEqual
(
doc
.
toprettyxml
(),
'<?xml version="1.0" ?>
\
n
'
'<curriculum status="public" company="example"/>
\
n
'
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/xml/dom/minidom.py
View file @
5598cc90
...
...
@@ -854,9 +854,8 @@ class Element(Node):
writer
.
write
(
indent
+
"<"
+
self
.
tagName
)
attrs
=
self
.
_get_attributes
()
a_names
=
sorted
(
attrs
.
keys
())
for
a_name
in
a
_names
:
for
a_name
in
a
ttrs
.
keys
()
:
writer
.
write
(
" %s=
\
"
"
%
a_name
)
_write_data
(
writer
,
attrs
[
a_name
].
value
)
writer
.
write
(
"
\
"
"
)
...
...
Misc/NEWS.d/next/Library/2018-10-27-21-11-42.bpo-34160.UzyPZf.rst
View file @
5598cc90
ElementTree
now preserves
the attribute order specified by the user.
ElementTree
and minidom now preserve
the attribute order specified by the user.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment