473,796 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BZip2 decompression and parsing XML

Hi.

I'm trying to disassemble bzipped file. If I use minidom.parseSt ring,
I'm getting this error:

Traceback (most recent call last):
File "./replications.py ", line 342, in ?

File "/usr/lib64/python2.4/xml/dom/minidom.py", line 1925, in
parseString
return expatbuilder.pa rseString(strin g)
File "/usr/lib64/python2.4/xml/dom/expatbuilder.py ", line 940, in
parseString
return builder.parseSt ring(string)
File "/usr/lib64/python2.4/xml/dom/expatbuilder.py ", line 223, in
parseString
parser.Parse(st ring, True)
xml.parsers.exp at.ExpatError: not well-formed (invalid token): line
538676, column 17

If I use minidom.parse, I'm getting this error:

Traceback (most recent call last):
File "./replications.py ", line 341, in ?
files.xml = minidom.parse(b z2.decompress(d ump))
File "/usr/lib64/python2.4/xml/dom/minidom.py", line 1915, in parse
return expatbuilder.pa rse(file)
File "/usr/lib64/python2.4/xml/dom/expatbuilder.py ", line 922, in
parse
fp = open(file, 'rb')
IOError

But XML parsed normally.

Code:

try:
handler = open(args[0], "r")
dump = handler.read()
handler.close()
except IOError, error:
print("Can't open dump: %s" % error)
sys.exit(1)

files.xml = minidom.parse(b z2.decompress(d ump))

Jun 27 '08 #1
1 2711
phasma wrote:
xml.parsers.exp at.ExpatError: not well-formed (invalid token): line
538676, column 17
Looks like your XML file is broken in line 538676.

try:
handler = open(args[0], "r")
This should read

handler = open(args[0], "rb")

Maybe that's your problem.

BTW, since you seem to parse a pretty big chunk of XML there, you should
consider using lxml. It's faster, more memory friendly, more feature-rich and
easier to use than minidom. It can also parse directly from a gzip-ed file or
a file-like object as provided by the bz2 module.

http://codespeak.net/lxml/

Stefan
Jun 27 '08 #2

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

Similar topics

0
1206
by: itzel | last post by:
Hello!! In using tarfile to group thousands of small files from a directory and then compress it. I already compress a group of files in my pc, but I need do it in a server and I'm testing the same procedure, but it doesn't work . A "ReadError" appear: "not a bzip2 file". I'm using this script: import os import tarfile
3
3272
by: Frederik Vanderhaegen | last post by:
Hey, I've written a http sniffer that monitors the traffic on port 80. This application works like it should be but there is one small problem. Suppose I run the application and I surf to www.google.be then I retrieve all the HTTP messages (Response and Request) but the content of the message is gzip encoded (http compression). Here you see the original message:
7
2436
by: giuseppe.cannella | last post by:
i need to read a row on a bzip2 file like the fgets function does on a text file can you help me to find this function thank
232
13360
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
3
3170
by: Sayudh27 | last post by:
Hi all, I need to decompress data packets that are being received over the network.The packets contain live data and I need to use the LZO algorithm for decompression.However,I am not sure as to exactly how to correctly apply it. Any help will be really appreciated... Thanks..
4
4189
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
The compression part of this code works fine for me, but the decompression part of this code does not. The output file from that is the same as the compressed file. What is wrong with my code? Thanks, Jon 'compression starts here Dim src As FileStream = File.OpenRead(Fn) Dim dst As FileStream = File.Create(Ofn) Dim cmp As New DeflateStream(dst, CompressionMode.Compress)
0
1273
by: Geky | last post by:
I'm trying to use BZip2 library but I receive always an access violation error. I use two different codes: bz_stream bzstream; ZeroMemory(&bzstream, sizeof(bzstream)); bzstream.bzalloc=NULL; bzstream.bzfree=NULL; bzstream.opaque=NULL;
13
4516
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
6
1391
by: Nilesh | last post by:
I have a query about Bzip2 in PHP. Let's say that i have a paragraph like: abcdbc nnotp iidhdmmc; uuidpssa -------End------- Now, i compress it using bzcompress() and store it in a mysql database.
3
2028
by: Stephany Young | last post by:
Does anyone have the source code for a C# implementation of the AR2000 Compression/Decompression algorithm that they might like to share?
0
9685
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
9533
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,...
1
10190
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,...
0
10019
tracyyun
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...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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.