Hello!
I'm using smgllib (ActivePython 2.3.2, build 230) and I have some trouble
with letters that has been coded, e.g. the letter å is coded å ä is
coded ä and ö is coded ö all according to the html standard.
I use the SGMLParser and when I feed method all the coded letter will be
stripped/eaten.
Why?
How do I fix this?
// Anders 8 2445
Anders Eriksson <am******@telia.com> writes: I'm using smgllib (ActivePython 2.3.2, build 230) and I have some trouble with letters that has been coded, e.g. the letter å is coded å ä is coded ä and ö is coded ö all according to the html standard.
I use the SGMLParser and when I feed method all the coded letter will be stripped/eaten.
Why? How do I fix this?
You probably want to use HTMLParser.HTMLParser instead (NOT the same
thing as htmllib.HTMLParser, note). It knows about XHTML, sgmllib &
htmllib don't. If you really want sgmllib, though (untested):
import htmlentitydefs
class MyParser(sgmllib.SGMLParser):
entitydefs = htmlentitydefs.entitydefs
def unknown_entityref(self, ref):
...
...
John
Anders Eriksson wrote: Hello!
I'm using smgllib (ActivePython 2.3.2, build 230) and I have some trouble with letters that has been coded, e.g. the letter å is coded å ä is coded ä and ö is coded ö all according to the html standard.
I use the SGMLParser and when I feed method all the coded letter will be stripped/eaten.
Why? How do I fix this?
The &something; "coding" for accented characters is called an entity in SGML.
These entities are all defined in the underlying DTD for your document. HTML
defines the "standard" entities you describe, like å, ä, etc... But
if the DTD for the document you're parsing does not include these entity
definitions, there's no reason why the parser should do anything with them, even
if silently ignoring them seems strange to me (I'd have expected a parsing error).
So there are two solutions:
- either your document is HTML, and you should use an HTML parser as it was
already suggested
- or your document is not HTML, and you should define all entities you may use
in your DTD. This is done for example with:
<!ENTITY auml ä>
(if you use the iso8859-1 encoding)
HTH
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Eric Brunel <er*********@N0SP4M.com> writes: Anders Eriksson wrote: Hello! I'm using smgllib (ActivePython 2.3.2, build 230) and I have some
[...] So there are two solutions: - either your document is HTML, and you should use an HTML parser as it was already suggested - or your document is not HTML, and you should define all entities you may use in your DTD. This is done for example with:
[...]
sgmllib only really does HTML.
John
On 30 Nov 2003 00:53:28 +0000, John J. Lee wrote: You probably want to use HTMLParser.HTMLParser instead (NOT the same thing as htmllib.HTMLParser, note). It knows about XHTML, sgmllib & htmllib don't.
å etc isn't XHTML, is it? AFAIK it is defined in HTML 4.
the strange thing is that the Character entity (i.e. å) is stripped
from the text. I don't want to change it since I'm feeding the output to a
browser.
I will try the HTMLParser instead but it seems to me that there is a bug in
SMGLParser...
// Anders
Anders Eriksson wrote: On 30 Nov 2003 00:53:28 +0000, John J. Lee wrote:
You probably want to use HTMLParser.HTMLParser instead (NOT the same thing as htmllib.HTMLParser, note). It knows about XHTML, sgmllib & htmllib don't. å etc isn't XHTML, is it? AFAIK it is defined in HTML 4.
the strange thing is that the Character entity (i.e. å) is stripped from the text. I don't want to change it since I'm feeding the output to a browser.
I will try the HTMLParser instead but it seems to me that there is a bug in SMGLParser...
If it's anything like the expat parser, it munches any undefined character
entity references (i.e. if there's a DTD but no definitions) unless you plug
in an appropriate entity reference subparser.
-Peter
Anders Eriksson <am******@telia.com> writes: On 30 Nov 2003 00:53:28 +0000, John J. Lee wrote:
You probably want to use HTMLParser.HTMLParser instead (NOT the same thing as htmllib.HTMLParser, note). It knows about XHTML, sgmllib & htmllib don't. å etc isn't XHTML, is it? AFAIK it is defined in HTML 4.
It'll cope with HTML too. It seems silly to be writing new code now
that will choke on XHTML.
the strange thing is that the Character entity (i.e. å) is stripped from the text. I don't want to change it since I'm feeding the output to a browser.
Did you read my post? Read the docs on the stuff in my code snippet.
I will try the HTMLParser instead but it seems to me that there is a bug in SMGLParser...
It's not a bug. That's just what it does, but you can easily override it.
John
Anders Eriksson <am******@telia.com> writes: the strange thing is that the Character entity (i.e. å) is stripped from the text. I don't want to change it since I'm feeding the output to a browser.
Inconvenient for you, but not strange. An SGML parser is supposed to
expand general entity references.
I will try the HTMLParser instead but it seems to me that there is a bug in SMGLParser...
No, it's consistent with the standard that the entity reference
disappears. The question is what replacement text has been put in its
place, and why can't you see it?
Dave Dubin
ddubin <dd****@lindev.isrl.uiuc.edu> writes: Anders Eriksson <am******@telia.com> writes:
[...] disappears. The question is what replacement text has been put in its place, and why can't you see it?
He can't see it because it's not there. From sgmllib.py:
# To be overridden -- handlers for unknown objects
def unknown_starttag(self, tag, attrs): pass
def unknown_endtag(self, tag): pass
def unknown_charref(self, ref): pass
def unknown_entityref(self, ref): pass
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: KhanyBoy |
last post by:
Hi,
this should test you guru's. I want a function that accepts text as an
argument and converts all & into & except where it is a html
character already such as , ", and of course &.
...
|
by: Robert Zierhofer |
last post by:
Hi all,
I currently face a problem with htmlentities and german "umlaute".
After moving my scripts to a new box (from Linux to FreeBSD) I had to
see that htmlentities is not working anymore....
|
by: ahsan Imam |
last post by:
Hello All,
I have this file and when I import the file in the python interpretor
I get the following error:
"__main__:1: DeprecationWarning: Non-ASCII character '\xc0' in file
trans.py on...
|
by: Anna |
last post by:
Hi,
I use the Swedish letters å,ä,ö in my HTML code and it works perfectly
in IE, but not in Netscape and Mozilla browsers. Does anyone know how
to fix it?
I use å for å, ä for ä and...
|
by: Colin Peters |
last post by:
Hi,
I'm reading a file and writing it to the html output for a page.
I've come across two difficulties which I would like to solve.
The files contain special characters from European...
|
by: Stephen Brown |
last post by:
I have a simple regex need and I've already wasted too much time on it
spinning in circles. Can a regex god help a stranded soul? I just need to
replace all non-escaped ampersands in a file. It...
|
by: John Nagle |
last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally
hit content which has something like "Design & Advertising", that is,
an "&" instead of an "&". Is there some way I can get...
|
by: John Nagle |
last post by:
I have XML replies in a DOM which contain entity escapes,
like "&". What's the proper way to replace them with
the ordinary characters? Preferably something that will work in
most browsers?
I...
|
by: yuanyun.ken |
last post by:
hi,dear all js gurus.
In my app, server responses some text like: ' '
and I need display these content in textarea.
But Html would convert specail characters to space, and ignore line...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |