Antw: XML::Parser Entities

Roland Bauer Roland.Bauer at mediaprint.at
Fri Nov 26 14:43:19 CST 1999


* * * vienna-pm-list * * *
Hallo Peter,

ich hab's nicht ausprobiert, aber ev ist das die antwort:
(aus der perl-xml-mailingliste)

roland

####################BEGIN###############

Phil Lanch <phil at aldigital.co.uk>
An:	"Perl-XML Mailing List" <perl-xml at listserv.activestate.com>
Datum: 	26.11.99 16.27 Uhr
Betreff: 	Re: &nbsp;, &ndash;, &ldquo

Guy Hulbert wrote:
> 
> On Fri, 26 Nov 1999, phil lanch wrote:
> 
>         <snip>
> 
> pl> <!DOCTYPE html [
> pl>     <!ENTITY nbsp "&#160;">
> pl>     <!ENTITY ndahs "&#XXX;">
> ?                ndash                  ?
> pl>     <!ENTITY ldquo "&#YYY;">
> pl> ]>
>         <snip>
> 
> ... looks like a missed opportunity to cut-and-paste :) ...

Hmmm... actually that _was_ cut-and-paste and the error was in the
original post... though of course I wouldn't flame anyone for making
tpyos... though of course you weren't flaming me...

More to the point, I've found the missing numbers for XXX and YYY:

<!DOCTYPE html [
    <!ENTITY nbsp "&#160;">
    <!ENTITY ndash "&#8211;">
    <!ENTITY ldquo "&#8220;">
]>

There are loads of these things (a.k.a. character entitiy sets) in the
XHTML spec at:

http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent

-- 

cheers

phil

witness relocation program alumnus

---
You are currently subscribed to perl-xml as: [Roland.Bauer at mediaprint.at]
To unsubscribe, forward this message to
         leave-perl-xml-115740Y at lyris.activestate.com
For non-automated Mailing List support, send email to  
         ListHelp at ActiveState.com



CC:	Perl-XML Mailing List <perl-xml at listserv.activestate.com> 


################### END###################





--
roland.bauer at mediaprint.at
internet-applikationen
TEL: +43-1-36000/3949

>>> "Peter J. Holzer" <hjp at wsr.ac.at> 26.11.1999  10.59 Uhr >>>
Hallo,

    das ist vielleicht gar keine Perl- sondern eine XML-Frage.

Ich verwende XML::Parser, um XHTML (mittels tidy -asxml aus HTML
generiert) zu parsen. Da kommen aber noch Entity References wie &ouml;
drin vor, die mir der Parser scheinbar wegschmeißt. Weiß wer, wie ich

* entweder den Parser dazu bringen kann, die Entities in das
  entsprechende Zeichen umzuwandeln

* oder welchen Handler ich installieren muß, um das selber zu machen
  (ExternEnt scheint es nicht zu sein) 

* oder ob ich durch Einfügen von <!ENTITY> im XML-File an geeigneter
  Stelle (wo?) &ouml; und Konsorten vordefinieren kann?

Ein Workaround, der mir einfällt, ist im XML-File alle &ouml; durch
&#214; zu ersetzen. Das funktioniert nämlich, wenn auch nicht besonders
schön.

ObCode:

#!/usr/bin/perl -w

use strict;
use XML::Parser;
use IO::File;

sub handle_start {
    my ($parser, $element, %attr) = (@_);

    print "handle_char: ";
    if ($element eq "meta") {
	if ($attr{name} eq 'description') {
	    print "description: ", $attr{content};
	}
	if ($attr{name} eq 'keywords') {
	    print "keywords: ", $attr{content};
	}
    }
    print "\n";
}

sub handle_char {
    my ($parser, $text) = (@_);

    print "handle_char: ";
    for my $i (qw/title h1 h2 h3 h4 h5 h6/) {
	if ($parser->within_element($i)) {
	    print "$i ";
	}
    }
    print "$text\n";
}

sub handle_externent {
    my ($parser, $base, $sysid, $pubid) = (@_);
    print "handle_externent: base = $base, sysid = $sysid, pubid = $pubid\n";
}

my $p1 = new XML::Parser (Handlers => {Start => \&handle_start,
				       Char => \&handle_char,
				       ExternEnt => \&handle_externent
				      },
			  ProtocolEncoding => 'ISO-8859-1',
			  NoExpand => 0
			);
my $fh = new IO::File ("test.xml", "r");
$p1->parse($fh);


-- 
   _  | Peter J. Holzer             | Nobody should ever have to be
|_|_) | Sysadmin WSR / Obmann LUGA  | ashamed if they have a secret love
| |   | hjp at wsr.ac.at               | for writing computer programs that
__/   | http://wsrx.wsr.ac.at/~hjp/ | actually work.  -- Donald E. Knuth

###
You are subscribed to vienna-pm-list
http://www.fff.at/fff/vienna.pm/



More information about the Vienna-pm mailing list