473,883 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does python's minidom support Chinese?

The following 4 lines of code parses an XML document
very well if the XML document contains only English
words.

But when I insert one Chinese character into the XML
document, then Python starts to complain when it hits
the Chinese character, saying that it is an invalid
token and thus it is not well-formed.

This is the complaint of Python:

ExpatError: not well-formed (invalid token): line 3,
column 7

line 3 and column 7 exactly pinpoints the 1st Chinese
character in the XML document.

The problem remains even if I try encoding="UTF-16" or
encoding="GB231 2" or encoding="GBK" in the xml
document.

Note that GB2312 and GBK are Chinese encodings.

Please give a hint. Thanks a lot!

The 4 lines of code I used is here:

# -*- coding: cp936 -*-
from xml.dom import minidom
xmldoc = minidom.parse(' test.xml')
print xmldoc.toxml()

_______________ _______________ ____
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

Jul 18 '05 #1
1 2990
Anthony Liu <an***********@ yahoo.com> wrote in message news:<ma******* *************** *************** *@python.org>.. .
The following 4 lines of code parses an XML document
very well if the XML document contains only English
words.

But when I insert one Chinese character into the XML
document, then Python starts to complain when it hits
the Chinese character, saying that it is an invalid
token and thus it is not well-formed.

This is the complaint of Python:

ExpatError: not well-formed (invalid token): line 3,
column 7

line 3 and column 7 exactly pinpoints the 1st Chinese
character in the XML document.
This is an XML problem on your end, not a minidom problem. That error
probably means that you are either omitting the XML declaration (and
thus defaulting to UTF-8 or UTF-16) or declaring a bogus encoding.

The problem remains even if I try encoding="UTF-16" or
encoding="GB231 2" or encoding="GBK" in the xml
document.


Well, you can't just go shopping about for oare it accordingly.

Back to minidom: even after you fix your XML problems you may still
have trouble with minidom because the expat reader has to understand
the encoding you're using. I think that it may use the Python codecs
model to find the encoding you declared, so you may just need to
install a Python Chinese codecs package, and you'll be all set. I'm
not entirely sure this si the case, though.
--Uche
http://uche.ogbuji.net
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2205
by: Hans Nowak | last post by:
Howdy y'all, The following works in Python 2.2.2: Python 2.2.2 (#37, Oct 14 2002, 17:02:34) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from xml.dom.minidom import Text >>> t = Text("foo") >>> t <DOM Text node "foo">
2
1904
by: python newbie | last post by:
Guys, Very beginner question. I'm importing xml.dom.minidom at the top of my file. I'm trying to figure out where the heck this is. According to Quick Python, there should be folders on my drive (using XP), under c:\python23, named xml, then underneath: dom, etc. But there isn't. I know that xml.dom.minidom is not built into sys.built_module_names,
3
2414
by: Thierry Lam | last post by:
Let's say I have the following xml tag: <para role="success">1</para> I can't figure out what kind of python xml.dom codes I should invoke to read the data 1? Any help please? Thanks Thierry
7
2121
by: fyleow | last post by:
Hi guys, I'm a student/hobbyist programmer interested in creating a web project. It's nothing too complicated, I would like to get data from an RSS feed and store that into a database. I want my website to get the information from the database and display parts of it depending on the criteria I set. I just finished an OO programming class in Java and I thought it would be a good idea to do this in C# since ASP.NET makes web...
1
1837
by: Ben Edwards (lists) | last post by:
I have been going through Dive into Python which up to now has been excellent. I am now working through Chapter 9, XML Processing. I am 9 pages in (p182) in the 'Parsing XML section. The following code is supposed to return the whole XML document (I have put ti at the end of this email): from xml.dom import minidom xmldoc = minidom.parse('/home/ben/diveintopython-5.4/py/kgp/binary.xml')
7
2156
by: kernel1983 | last post by:
I'm try to build a bundle on OS X, so I write a simple python script for a test: #!/usr/bin/env python import EasyDialogs EasyDialogs.Message("Hello,Mac!") This runs OK,but when I try to replace "Hello,Mac!" with chinese, it can't be display rightly.
0
293
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 356 open ( -1) / 3756 closed (+11) / 4112 total (+10) Bugs : 968 open (+10) / 6673 closed (+16) / 7641 total (+26) RFE : 254 open ( +3) / 282 closed ( +2) / 536 total ( +5) New / Reopened Patches ______________________
40
2765
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I'm really annoyed at Python - and not for the reasons already mentioned on this list. Everyone know that programming is supposed to be a dark art, nearly impossible to learn. Computer code is supposed to be something impossible to read to the common person and yet reveal their secrets to the initiated - just remember the code displayed in the Matrix... Python takes all of that away. It is just too readable. Even beginners can...
1
2443
by: Paul McGuire | last post by:
Back in May, there was quite an extensive discussion of whether or not Python should support Unicode identifiers (with the final result being that this would be supported in Python 3). In my periodic googling for pyparsing users, I stumbled upon Zhpy, a preprocessor that renders on the fly Chinese Python keywords and indentifiers written using traditional Chinese characters into ASCII counterparts, and then executes the resulting script. ...
0
9944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9793
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11151
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7974
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4619
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.