Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the doctype when parsing and unparsing #351

Open
Ravencentric opened this issue Jul 14, 2024 · 0 comments
Open

Preserve the doctype when parsing and unparsing #351

Ravencentric opened this issue Jul 14, 2024 · 0 comments

Comments

@Ravencentric
Copy link

Current behavior:
xmltodict discards DOCTYPE.

Expected behavior:
xmltodict should keep DOCTYPE

Reproduction:

import xmltodict

xml = """\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library PUBLIC "-//Example//DTD Library 1.0//EN" "http://www.example.com/DTD/library.dtd">
<library>
    <book>
        <title>XML Basics</title>
        <author>John Doe</author>
        <published>2020</published>
    </book>
    <book>
        <title>Advanced XML Techniques</title>
        <author>Jane Smith</author>
        <published>2021</published>
    </book>
</library>
"""

parsed = xmltodict.parse(xml)
unparsed = xmltodict.unparse(parsed, pretty=True)
print(unparsed)
# <?xml version="1.0" encoding="utf-8"?>
# <library>
#         <book>
#                 <title>XML Basics</title>
#                 <author>John Doe</author>
#                 <published>2020</published>
#         </book>
#         <book>
#                 <title>Advanced XML Techniques</title>
#                 <author>Jane Smith</author>
#                 <published>2021</published>
#         </book>
# </library>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant