Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 529285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:04:33+00:00 2026-05-13T09:04:33+00:00

I tried: document.doctype = xml.dom.minidom.DocumentType(‘html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN DTD/xhtml1-strict.dtd’) There is no

  • 0

I tried:

document.doctype = xml.dom.minidom.DocumentType('html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"')

There is no doctype in the output. How to fix without inserting it by hand?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:04:33+00:00Added an answer on May 13, 2026 at 9:04 am

    You shouldn’t instantiate classes from minidom directly. It’s not a supported part of the API, the ownerDocument​s won’t tie up and you can get some strange misbehaviours. Instead use the proper DOM Level 2 Core methods:

    >>> imp= minidom.getDOMImplementation('')
    >>> dt= imp.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd')
    

    (‘DTD/xhtml1-strict.dtd’ is a commonly-used but wrong SystemId. That relative URL would only be valid inside the xhtml1 folder at w3.org.)

    Now you’ve got a DocumentType node, you can add it to a document. According to the standard, the only guaranteed way of doing this is at document creation time:

    >>> doc= imp.createDocument('http://www.w3.org/1999/xhtml', 'html', dt)
    >>> print doc.toxml()
    <?xml version="1.0" ?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html/>
    

    If you want to change the doctype of an existing document, that’s more trouble. The DOM standard doesn’t require that DocumentType nodes with no ownerDocument be insertable into a document. However some DOMs allow it, eg. pxdom. minidom kind of allows it:

    >>> doc= minidom.parseString('<html xmlns="http://www.w3.org/1999/xhtml"><head/><body/></html>')
    >>> dt= minidom.getDOMImplementation('').createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd')
    >>> doc.insertBefore(dt, doc.documentElement)
    <xml.dom.minidom.DocumentType instance>
    >>> print doc.toxml()
    <?xml version="1.0" ?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns="http://www.w3.org/1999/xhtml"><head/><body/></html>
    

    but with bugs:

    >>> doc.doctype
    # None
    >>> dt.ownerDocument
    # None
    

    which may or may not matter to you.

    Technically, the only reliable way per the standard to set a doctype on an existing document is to create a new document and import the whole of the old document into it!

    def setDoctype(document, doctype):
        imp= document.implementation
        newdocument= imp.createDocument(doctype.namespaceURI, doctype.name, doctype)
        newdocument.xmlVersion= document.xmlVersion
        refel= newdocument.documentElement
        for child in document.childNodes:
            if child.nodeType==child.ELEMENT_NODE:
                newdocument.replaceChild(
                    newdocument.importNode(child, True), newdocument.documentElement
                )
                refel= None
            elif child.nodeType!=child.DOCUMENT_TYPE_NODE:
                newdocument.insertBefore(newdocument.importNode(child, True), refel)
        return newdocument
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: <!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 xml:lang=en
<!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> <title>Validation POC</title> <script
I've included jQuery by doing this: <?xml version=1.0?> <!DOCTYPE window SYSTEM chrome://orkutmanager/locale/browser.dtd> <overlay id=omcore
XML documents can be localized by referring to an external DTD document that contains
Using an Document DTD I did the following: file.xsl: <!DOCTYPE xsl:stylesheet[ <!ENTITY red rgb(255,0,0)>
I use the Java (6) XML-Api to apply a xslt transformation on a html-document
I tried some simple examples like the following one: <?xml version=1.0 encoding=ISO-8859-1 standalone=no?> <!DOCTYPE
I wrote a svg file like this: <?xml version=1.0 encoding=UTF-8 ?> <!DOCTYPE svg PUBLIC
I have an XHTML 1.0 Strict document in which I'm trying to make Shadowbox
I've tried: $(document).ready(function(){ $(parent.top).find('.IAgreeCheckBox:first').prop(checked, true); }); to no avail.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.