Hi,
I am parsing an XML file that includes chineses characters, like ^
評評啖啖才是眞. 細氺長锍才是愛 or ヘアアイロン... The problem is that I get an error like:
UnicodeEncodeer ror:'charmap' codec can't encode characters in position....
The thing is that I would like to ignore it and parse all the characters
less these ones. So, could anyone help me? I suppose that I can catch an
exception that ignores it or maybe use any function that detects this
chinese characters and after that ignore them.
Thanks!!
Fabian 3 3030
On Mon, 22 Oct 2007 21:24:40 +0200, Fabian L贸pez wrote:
I am parsing an XML file that includes chineses characters, like ^
uu鍟栧晼鎵嶆槸w .鎵塋閿嶆墠鏄 or 銉樸偄銈€偆銉* 銉... The problem is that I get an error like:
UnicodeEncodeer ror:'charmap' codec can't encode characters in
position..
You say you are *parsing* the file but this is an *encode* error. Parsing
means *decoding*.
You have to show some code and the actual traceback to get help. Crystal
balls are not that reliable. ;-)
Ciao,
Marc 'BlackJack' Rintsch
Fabian L贸pez wrote:
Thanks Mark, the code is like this. The attrib name is the problem:
from lxml import etree
context = etree.iterparse ("file.xml")
for action, elem in context:
if elem.tag == "weblog":
print action, elem.tag , elem.attrib["name"],elem.attrib["url"],
The problem is the print statement. Looks like your terminal encoding (that
Python needs to encode the unicode string to) can't handle these unicode
characters.
Stefan
On 10/23/07, Stefan Behnel <st************ ******@web.dewr ote:
Fabian L髉ez wrote:
Thanks Mark, the code is like this. The attrib name is the problem:
from lxml import etree
context = etree.iterparse ("file.xml")
for action, elem in context:
if elem.tag == "weblog":
print action, elem.tag , elem.attrib["name"],elem.attrib["url"],
The problem is the print statement. Looks like your terminal encoding (that
Python needs to encode the unicode string to) can't handle these unicode
characters.
I agree. For Japanese, you should know the exactly encoding name, and
convert them, just like:
print text.encoding(' encoding')
--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kobi Lurie |
last post by:
Hello all,
I'm trying to make a simple script
beginner level script, with just functions.
it uses the functions:
file_get_contents
substr
taking into an array the text substr took
then
array_count_values
|
by: Knackeback |
last post by:
Hi, I wrote a XML file with GNU emacs 21.2.2 and with
chinese character content encoded in UTF-8.
I wrote something like:
<?xml version="1.0" encoding="UTF-8"?>
<test>
<chinese>蓟</chinese>
<chinese>奈</chinese>
</test>
|
by: Dean A. Hoover |
last post by:
I am attempting to parse an extremely
simple xml file that has an embedded DTD
using java sax2. Here is the xml file:
<?xml version="1.0" ?>
<!DOCTYPE foo >
<foo>
<bar/>
</foo>
|
by: Agnes |
last post by:
In my .net ,i need to generate an xml file , however, user may input a
chinese character, Then , the xml will got something unknow characters. the
following is my code, Does anyone know how to solve it ??
Private Sub Init()
With AMSXML
..Formatting = Formatting.Indented
..Indentation = 4
..IndentChar = " "
..WriteStartDocument()
|
by: pabv |
last post by:
Hello all,
I am having a few issues with encoding to chinese characters and
perhaps someone might be able to assist.
At the moment I am only able to see chinese characters when displayed
as part of a datagrid. When an input textbox is displayed it does not
display chinese characters, but rather the unicode characters stored
in the mssql 2000 server backend.
| |
by: K |
last post by:
I've an XML file in UTF-8.
It contains some chinese characters ( both simplified chinese and
traditional chinese).
In loading the XML file with MSXML parser, I used the below code to retrieve
the data in a node. The CString was then display in CListCtrl. For the
traditional chinese characters, they were shown correctly, but for
simplified characters, I encounted many "?", but some characters were
correct.
|
by: st.frey |
last post by:
I've got a problem with importing chinese characters into a mysql-table
and have read several mailings but didn't find a solution.
i have a utf-8 text file that contains chinese characters. the table
where i want to import the data using "load data local infile" has
collation utf8_unicode_ci. but after the import is done, the chinese
characters are converted into so strange characters. to show the
chinese symbols in a php-script i use...
|
by: Clive Green |
last post by:
Hello peeps,
I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and
writing MP3 tags). I have been using PHP on the command line (Mac OS X
Unix shell, to be precise), and am getting on more or less OK.
So far, I have managed to parse my tab-delimited .txt file properly into
an array, and then use this array to update the tags on a bunch of MP3
audio files. Nice.
|
by: csl |
last post by:
I have to open and parse an xml file (with some xml elements in Chinese) in
C#, VS2003. I can open the file. However, when I read the xml elements,
it's showing "?????". Am I doing something wrong and how can I fix it?
Thanks,
Chris
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing, and deployment梬ithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
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...
| |