CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
XML::Parser problems with ....

 



KingChris
Deleted

Sep 27, 2000, 5:04 AM

Post #1 of 1 (634 views)
XML::Parser problems with .... Can't Post

I use the XML::Parser from Larry and Clark Copper.
I want to parse a XML-File, save the Data an create a HTML File. The problem is, that the parser transform ö to and to ü and to ß etc.....
Can anybody help me ?
(if i change encodings (utf-8, us-ascii.... )i get an not well formed error !!)

SourceCode:

#!/usr/local/bin/perl -w

use XML::Parser;
$file = "test.xml";

$treename = "";
$outputname="";
$headname="";
$i=0;
$cachetreename="";
die "Can't find file \"$file\""
unless -f $file;

my $parser = new XML::Parser(ErrorContext => 2);

$parser->setHandlers(Start => \&start_handler,
Char => \&char_handler,
End => \&end_handler);

$parser->parsefile($file, ProtocolEncoding=> 'windows-1250');


sub start_handler
{

$i++;
my ($p, $data) = @_;
if (length($treename) < 1)
{
$treename = ("$data");
$headname = $data;
}
else
{
$outputname = "$treename-$data";
$treename = $outputname;
}
$keyname=$treename;
}


sub end_handler
{
$i++;

my ($p, $data) = @_;
$treename =~ s/-$data//g;


}

sub char_handler
{

$i++;
my ($p, $data) = @_;

if (length($data)!=0)
{

if ($cachetreename==$treename)
{

$result{$treename}="$result{$treename} $data";

}

else
{
$result{$treename} = $data;
}
}
$cachetreename;
}

foreach $zeile (keys(%result))
{
print "-----------------".$zeile.":".$result{$zeile}."\n";
}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives