By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

Add encoding to XML element

P: 1

I've been working on a script that generates a XML document, and output needs to have encoding "ISO-8859-1" defined in the first <?xml ...> tag.

I found this example on

Expand|Select|Wrap|Line Numbers
  1. import xml.dom.minidom
  2. #import xml.dom.ext as domExt
  4. dom = xml.dom.minidom.getDOMImplementation()
  6. doctype = dom.createDocumentType("html",
  7.               "-//W3C//DTD XHTML 1.0 Strict//EN",
  8.               "" )
  10. doc = dom.createDocument( None, "html", doctype )
  11. (... snip ...)
This should produce something like
Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3.   "">
  4. <html/>
However, when I try it, the encoding part is not generated. Also, AFAIK "UTF-8" is the default coding and I require something else...

So how do you set what encoding to use?
Nov 21 '06 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 6,596
I don't have any experience, but section 8 of the 2.5 docs have some interesting looking tidbits like:

8.4 htmlentitydefs -- Definitions of HTML general entities

This module defines three dictionaries, name2codepoint, codepoint2name, and entitydefs. entitydefs is used by the htmllib module to provide the entitydefs member of the HTMLParser class. The definition provided here contains all the entities defined by XHTML 1.0 that can be handled using simple textual substitution in the Latin-1 character set (ISO-8859-1)

entitydefs A dictionary mapping XHTML 1.0 entity definitions to their replacement text in ISO Latin-1.
Nov 21 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.