Dear All,
I am having some data which will be stored in XML format and this needs to be parsed using the parser module XML::Parser and XML::Parser::Expat.
This data consists of some special characters like ", , , , , , , ".
But when I try to parse the particular record with these special characters using the method parse(), I got an error "not well-formed (invalid token)".
Here I am posing my code:
sub parse {
my $self = shift;
my $arg = shift;
my @expat_options = ();
my ($key, $val);
while (($key, $val) = each %{$self}) {
push(@expat_options, $key, $val)
unless exists $self->{Non_Expat_Options}->{$key};
}
my $expat = new XML::Parser::Expat(@expat_options, @_);
my %handlers = %{$self->{Handlers}};
my $init = delete $handlers{Init};
my $final = delete $handlers{Final};
$expat->setHandlers(%handlers);
if ($self->{Base}) {
$expat->base($self->{Base});
}
&$init($expat)
if defined($init);
my @result = ();
my $result;
eval {
$result = $expat->parse($arg);
};
my $err = $@;
if ($err) {
$expat->release;
die $err;
}
if ($result and defined($final)) {
if (wantarray) {
@result = &$final($expat);
}
else {
$result = &$final($expat);
}
}
$expat->release;
return unless defined wantarray;
return wantarray ? @result : $result;
}
where $arg will contain the xml data to be parsed which is having the special characters to be parsed.
The xml data will look like this :
<record>
<source-app >ABC</source-app>
<ref-type>6</ref-type>
<contributors>
<authors>
<author>
<style face="normal" font="default" size="100%">Dvoøák, Petr
+</style>
</author>
</authors>
</contributors>
<titles>
<title>
<style face="normal" font="default" size="100%">Systematická te
+ologie I : ø*mskokatolická perspektiva</style>
</title>
</titles>
<pages>
<style>285 s.</style>
</pages>
<edition>
<style>1. vyd.</style>
</edition>
<keywords>
<keyword>
<style>uèen* katolické c*rkve</style>
</keyword>
</keywords>
<dates>
<year>
<style>1996</style>
</year>
</dates>
<pub-location>
<style>Brno
Praha</style>
</pub-location>
<publisher>
<style>Centrum pro studium demokracie a kultury ;
Èeská køe
+sanská akademie</style>
</publisher>
<notes>
<style>uspoøádali Francis S. Fiorenza a John P. Galvin ; [z angl
+iètiny pøeložili Petr Dvoøák ... et al.]
20 cm
Pozn.
+;Pozn. o autorech traktátù
Zkratky
Bibliogr.
Odkazy na
+lit.
Jmenný a vìcný rejstø*k</style>
</notes>
</record>
The data corresponding to the tags in the above xml is Czec. My problem is that the Parser.pm is not able to parse these characters.
Could anyone please help me out in solving this one.
Thanks alot.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.