473,657 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SGMLParser eats ä etc

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
Jul 18 '05 #1
8 2454
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 &aring; ä is
coded &auml; and ö is coded &ouml; 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.HTML Parser instead (NOT the same
thing as htmllib.HTMLPar ser, note). It knows about XHTML, sgmllib &
htmllib don't. If you really want sgmllib, though (untested):

import htmlentitydefs

class MyParser(sgmlli b.SGMLParser):
entitydefs = htmlentitydefs. entitydefs

def unknown_entityr ef(self, ref):
...

...
John
Jul 18 '05 #2
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 &aring; ä is
coded &auml; and ö is coded &ouml; 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 &aring;, &auml;, 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

Jul 18 '05 #3
Eric Brunel <er*********@N0 SP4M.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
Jul 18 '05 #4
On 30 Nov 2003 00:53:28 +0000, John J. Lee wrote:
You probably want to use HTMLParser.HTML Parser instead (NOT the same
thing as htmllib.HTMLPar ser, note). It knows about XHTML, sgmllib &
htmllib don't.

&aring; etc isn't XHTML, is it? AFAIK it is defined in HTML 4.

the strange thing is that the Character entity (i.e. &aring;) 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
Jul 18 '05 #5
Anders Eriksson wrote:

On 30 Nov 2003 00:53:28 +0000, John J. Lee wrote:
You probably want to use HTMLParser.HTML Parser instead (NOT the same
thing as htmllib.HTMLPar ser, note). It knows about XHTML, sgmllib &
htmllib don't.

&aring; etc isn't XHTML, is it? AFAIK it is defined in HTML 4.

the strange thing is that the Character entity (i.e. &aring;) 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
Jul 18 '05 #6
Anders Eriksson <am******@telia .com> writes:
On 30 Nov 2003 00:53:28 +0000, John J. Lee wrote:
You probably want to use HTMLParser.HTML Parser instead (NOT the same
thing as htmllib.HTMLPar ser, note). It knows about XHTML, sgmllib &
htmllib don't. &aring; 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. &aring;) 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
Jul 18 '05 #7
Anders Eriksson <am******@telia .com> writes:
the strange thing is that the Character entity (i.e. &aring;) 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

Jul 18 '05 #8
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_startta g(self, tag, attrs): pass
def unknown_endtag( self, tag): pass
def unknown_charref (self, ref): pass
def unknown_entityr ef(self, ref): pass
John
Jul 18 '05 #9

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

Similar topics

6
2638
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 &amp; except where it is a html character already such as &nbsp;, &quot;, and of course &amp;. If there is already a php function for this I would like to know, but if not, what is the GREP equivilent? Thanks
13
8520
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. The BSD Server (FreeBSD 5.1.2) runs PHP 4.3.9 and Apache 2 as well as the Linux Server does/did too. I also tried defining the charset with ISO 8859-1 as 3rd parameter in htmlentities but without a result.
2
4501
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 line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details" I am not sure what encoding to use. I am not sure where to look. I
9
5619
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 &aring for å, &auml for ä and &ouml for ö. Thanx
8
1271
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 alphabets, namely those which have the two little dots above the vowels called umlauts. Normally, these are rendered in html using "%auml;", but in the file
2
263
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 needs to skip escaped ampersands such as &amp; and  &+; will get the escaped ampersands (some inproper escapes will slip buy, but good enough for my purposes), but I need to replace all the ampersands that aren't escaped example:
7
4607
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 "&amp;". Is there some way I can get BeautifulSoup to clean those up? There are various parsing options related to "&" handling, but none of them seem to do quite the right thing. If I write the BeautifulSoup parse tree back out with "prettify", the loose "&" is still in there. So...
3
8179
by: John Nagle | last post by:
I have XML replies in a DOM which contain entity escapes, like "&amp;". What's the proper way to replace them with the ordinary characters? Preferably something that will work in most browsers? I know about ".innerText", but that's not portable; some browsers convert escapes when reading from innerText and some don't. John Nagle
3
1901
by: yuanyun.ken | last post by:
hi,dear all js gurus. In my app, server responses some text like: '&nbsp;&nbsp; ' and I need display these content in textarea. But Html would convert specail characters to space, and ignore line break. How can I display the content literally without any change? Any help is greatly appreciated, and Thanks for any reply in advance.
0
8324
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
8842
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
8516
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
7353
agi2029
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...
1
6176
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
5642
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
4173
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 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.