Hi,
I think I ran into a bug in the XML SAX parser.
part of my program consist of reading a rather large XML file (about
10Mb) containing a few thousand elements.
I have the following problem. Sometimes that SAX parses misreads a
line.
Let me explain: the XML file contains a few thousand lines like this:
"
<TargetRef>WINO SSPI:Storage@@n 91c90a.cmc.com</TargetRef>
"
where 'n91c90a.cmc.co m' is the name of a system and thus changes per
system.
I a few cases, the SAX parser misreads the line. The parser sometimes
plits characters the line in:
"WINOSSPI:Stora ge@@n" and "91c90a.cmc.com ".
I put a 'print characters' line in the 'characters' method of the
parser that is how I found out.
It only happens for a few of the thousand lines but you can imagine
that is very annoying.
I checked for errors in the XML file but the file seems ok.
Is this a bug or am I doing something wrong?
I am new to Python.
I am using Python 2.4.1, pyWin32 extension 2.4 and PyXML 0.8.4
Any help very much appreciated.
Kris 4 3695 mi*****@skynet. be wrote: I think I ran into a bug in the XML SAX parser.
part of my program consist of reading a rather large XML file (about 10Mb) containing a few thousand elements. I have the following problem. Sometimes that SAX parses misreads a line. Let me explain: the XML file contains a few thousand lines like this: " <TargetRef>WINO SSPI:Storage@@n 91c90a.cmc.com</TargetRef> " where 'n91c90a.cmc.co m' is the name of a system and thus changes per system. I a few cases, the SAX parser misreads the line. The parser sometimes plits characters the line in: "WINOSSPI:Stora ge@@n" and "91c90a.cmc.com ". I put a 'print characters' line in the 'characters' method of the parser that is how I found out. It only happens for a few of the thousand lines but you can imagine that is very annoying.
I checked for errors in the XML file but the file seems ok.
Is this a bug or am I doing something wrong?
it's not a bug; the parser is free to split up character runs (due to buffering,
entities or character references, etc). it's up to you to merge character runs
into strings.
</F>
Fredrik Lundh schreef: mi*****@skynet. be wrote:
I think I ran into a bug in the XML SAX parser.
part of my program consist of reading a rather large XML file (about 10Mb) containing a few thousand elements. I have the following problem. Sometimes that SAX parses misreads a line. Let me explain: the XML file contains a few thousand lines like this: " <TargetRef>WINO SSPI:Storage@@n 91c90a.cmc.com</TargetRef> " where 'n91c90a.cmc.co m' is the name of a system and thus changes per system. I a few cases, the SAX parser misreads the line. The parser sometimes plits characters the line in: "WINOSSPI:Stora ge@@n" and "91c90a.cmc.com ". I put a 'print characters' line in the 'characters' method of the parser that is how I found out. It only happens for a few of the thousand lines but you can imagine that is very annoying.
I checked for errors in the XML file but the file seems ok.
Is this a bug or am I doing something wrong?
it's not a bug; the parser is free to split up character runs (due to buffering, entities or character references, etc). it's up to you to merge character runs into strings.
</F>
Thanks for the feedback,
but how do I detect that the parser has split up the characters? I gues
I need to detect it in order to reconstruct the complete string mi*****@skynet. be wrote: but how do I detect that the parser has split up the characters? I gues I need to detect it in order to reconstruct the complete string
Don't try to detect it. Instead, assume it always happens, and collect
the strings in characters(), rather than processing them. Do something
like this
def startElement(se lf, ...):
self.chardata = ""
def characters(self , data):
self.chardata += data
def endElement(self , ...):
process(self.ch ardata)
This is simplified - you might have to deal with nested elements,
somehow.
Regards,
Martin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paulo Pinto |
last post by:
Hi,
does anyone know of a Python package that
is able to load XML like the XML::Simple
Perl package does?
For those that don't know it, this package
maps the XML file to a dictionary.
|
by: Jean de Largentaye |
last post by:
Hi,
I need to parse a subset of C (a header file), and generate some unit
tests for the functions listed in it. I thus need to parse the code,
then rewrite function calls with wrong parameters. What I call "shaking
the broken tree" :)
I chose to make my UT-generator in Python 2.4. However, I am now
encountering problems in choosing the right parser for the job. I
struggle in choosing between the inappropriate, the out-of-date, the...
|
by: Karalius, Joseph |
last post by:
Can anyone explain what is happening here? I haven't found any useful info
on Google yet.
Thanks in advance.
mmagnet:/home/jkaralius/src/zopeplone/Python-2.3.5 # make
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -o Modules/python.o
Modules/python.c
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -o...
|
by: Himanshu Garg |
last post by:
Hello,
I am trying to pinpoint an apparent bug in HTML::Parser. The
encoding of the text seems to change incorrectly if the locale isn't
set properly.
However Parser.pm in the directory
(/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/HTML/)
doesn't seem to contain the "real" parsing statements.
|
by: Joel Hedlund |
last post by:
Hi!
I have a possibly dumb question about imports. I've written two python
modules:
parser.py
------------------------------------
class Parser(object):
"my parser"
------------------------------------
| |
by: thewarden |
last post by:
I've come into a situation where I require to have BBCode parsed, this
includes the standard tags supported by PEAR package HTML_BBCodeParser
and custom BBCode tags I've added myself.
My problem is this, I've discovered that when an value has a space
within the value the value is truncated at the first occurrence of the
space. This applies to a URL, image file names and any additional
attribute values (alt, style, etc.). This issue is...
|
by: Marc Gravell |
last post by:
In Linq, you can apparently get a meaningful body from and
expression's .ToString(); random question - does anybody know if linq
also includes a parser? It just seemed it might be a handy way to
write a safe but easy implementation (i.e. no codedom) for an
IBindingListView.Filter (by compiling to a Predicate<T>).
Anybody know if this is possible at all?
Marc
|
by: UncleRic |
last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro
I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env):
PERL5LIB=/Users/Ric/Library/Perl/
ls
XML-Parser-2.34/ XML-Parser-2.34.tar
|
by: Just Another Victim of the Ambient Morality |
last post by:
Is pyparsing really a recursive descent parser? I ask this because
there are grammars it can't parse that my recursive descent parser would
parse, should I have written one. For instance:
from pyparsing import *
grammar = OneOrMore(Word(alphas)) + Literal('end')
grammar.parseString('First Second Third end')
|
by: arvindkgs |
last post by:
Iam using c lexer that is flex generated and a c++ parser that is bison generated. i have modified the parser to acccept only string input.
I am calling the parser function yyparse in a loop and reading line by line of user input. I stop the loop if the input is "quit".
The problem i am facing is that when input does'nt match any rule then, the parser stops abruptly, and at next iteration starts off
at same state, expecting the rule...
|
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—planning, coding, testing, and deployment—without 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |