| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a4ca6e8 commit 9bd9c74
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -157,6 +157,7 @@ module documentation. This section lists the differences between the API and | |||
| 157 | 157 | .. versionchanged:: next | |
| 158 | 158 | Namespace declarations missing for the serialized element | |
| 159 | 159 | and its attributes are now written. | |
| 160 | + It now works for :class:`!DocumentFragment` nodes. | ||
| 160 | 161 | ||
| 161 | 162 | .. method:: Node.toxml(encoding=None, standalone=None) | |
| 162 | 163 | ||
@@ -179,6 +180,9 @@ module documentation. This section lists the differences between the API and | |||
| 179 | 180 | .. versionchanged:: 3.9 | |
| 180 | 181 | The *standalone* parameter was added. | |
| 181 | 182 | ||
| 183 | + .. versionchanged:: next | ||
| 184 | + It now works for :class:`!DocumentFragment` nodes. | ||
| 185 | + | ||
| 182 | 186 | .. method:: Node.toprettyxml(indent="\t", newl="\n", encoding=None, \ | |
| 183 | 187 | standalone=None) | |
| 184 | 188 | ||
@@ -207,6 +211,7 @@ module documentation. This section lists the differences between the API and | |||
| 207 | 211 | .. versionchanged:: next | |
| 208 | 212 | Whitespace is no longer added inside an element with mixed content | |
| 209 | 213 | or marked with ``xml:space="preserve"``. | |
| 214 | + It now works for :class:`!DocumentFragment` nodes. | ||
| 210 | 215 | ||
| 211 | 216 | .. _dom-example: | |
| 212 | 217 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -725,6 +725,12 @@ xml | |||
| 725 | 725 | rather than defaulted from the DTD. | |
| 726 | 726 | (Contributed by Jason Orendorff and Serhiy Storchaka in :gh:`44871`.) | |
| 727 | 727 | ||
| 728 | + * The :meth:`~xml.dom.minidom.Node.writexml`, | ||
| 729 | + :meth:`~xml.dom.minidom.Node.toxml` and | ||
| 730 | + :meth:`~xml.dom.minidom.Node.toprettyxml` methods | ||
| 731 | + now work for :class:`!DocumentFragment` nodes in :mod:`xml.dom.minidom`. | ||
| 732 | + (Contributed by Serhiy Storchaka in :gh:`54092`.) | ||
| 733 | + | ||
| 728 | 734 | * :class:`~xml.etree.ElementTree.XMLPullParser` and | |
| 729 | 735 | :func:`~xml.etree.ElementTree.iterparse` now support the *target* parameter. | |
| 730 | 736 | The reported object is the value returned by the corresponding method of | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -571,6 +571,21 @@ def testWriteXML(self): | |||
| 571 | 571 | dom.unlink() | |
| 572 | 572 | self.assertEqual(str, domstr) | |
| 573 | 573 | ||
| 574 | + def testWriteXMLDocumentFragment(self): | ||
| 575 | + dom = parseString('<doc><a b="c"/>text<!--comment--></doc>') | ||
| 576 | + frag = dom.createDocumentFragment() | ||
| 577 | + for node in list(dom.documentElement.childNodes): | ||
| 578 | + frag.appendChild(node) | ||
| 579 | + self.assertEqual(frag.toxml(), '<a b="c"/>text<!--comment-->') | ||
| 580 | + self.assertEqual(frag.toprettyxml(), | ||
| 581 | + '<a b="c"/>\ntext\n<!--comment-->\n') | ||
| 582 | + # the fragment itself does not add a level of indentation | ||
| 583 | + writer = io.StringIO() | ||
| 584 | + frag.writexml(writer, " ", " ", "\n") | ||
| 585 | + self.assertEqual(writer.getvalue(), | ||
| 586 | + ' <a b="c"/>\n text\n <!--comment-->\n') | ||
| 587 | + self.assertEqual(dom.createDocumentFragment().toxml(), '') | ||
| 588 | + | ||
| 574 | 589 | def testWriteXMLNamespaceDeclarations(self): | |
| 575 | 590 | dom = Document() | |
| 576 | 591 | root = dom.appendChild( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -515,6 +515,10 @@ class DocumentFragment(Node): | |||
| 515 | 515 | def __init__(self): | |
| 516 | 516 | self.childNodes = NodeList() | |
| 517 | 517 | ||
| 518 | + def writexml(self, writer, indent="", addindent="", newl=""): | ||
| 519 | + for node in self.childNodes: | ||
| 520 | + node.writexml(writer, indent, addindent, newl) | ||
| 521 | + | ||
| 518 | 522 | ||
| 519 | 523 | class Attr(Node): | |
| 520 | 524 | __slots__=('_name', '_value', 'namespaceURI', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + Implement :meth:`~xml.dom.minidom.Node.writexml` for document fragments | ||
| 2 | + in :mod:`xml.dom.minidom`, | ||
| 3 | + so that :meth:`~xml.dom.minidom.Node.toxml` and | ||
| 4 | + :meth:`~xml.dom.minidom.Node.toprettyxml` now work for them. | ||
| 5 | + They write the children of the fragment, | ||
| 6 | + without adding a level of indentation. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments