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)".
Could anyone please help me out in solving this one.
Thanks alot.
6 4405
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)".
Could anyone please help me out in solving this one.
Thanks alot.
Without seeing your code or the sample data, we have no way of knowing what you are doing. Please post your code ( in the appropriate code tags) and a sample of the data you are parsing and we will have a look.
Regards,
Jeff
Without seeing your code or the sample data, we have no way of knowing what you are doing. Please post your code ( in the appropriate code tags) and a sample of the data you are parsing and we will have a look.
Regards,
Jeff
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á teologie 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øesanská akademie</style>
-
</publisher>
-
<notes>
-
<style>uspoøádali Francis S. Fiorenza a John P. Galvin ; [z angliè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>
Please have a look at it and help me.
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á teologie 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øesanská akademie</style>
-
</publisher>
-
<notes>
-
<style>uspoøádali Francis S. Fiorenza a John P. Galvin ; [z angliè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>
Please have a look at it and help me.
Can anybody help me out on this
What language uses the special characters you are encountering? The problem is the encoding. You more that likely need to use the utf-8 encoding in your XML document. This module does support the utf-8 encoding. As well as others except for Japanese, I believe.
What language uses the special characters you are encountering? The problem is the encoding. You more that likely need to use the utf-8 encoding in your XML document. This module does support the utf-8 encoding. As well as others except for Japanese, I believe.
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.
Can you please give me a script which can parse these special characters i.e. a method to handle these characters using XML::Parser module.
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.
Can you please give me a script which can parse these special characters i.e. a method to handle these characters using XML::Parser module.
Could anybody help me out on this issue please?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rutger Claes |
last post by:
I'm having troubles getting the euro sign through an XML parser.
With the following test code:
<?php
$string = "<root><test>€</test></root>";
$parser = xml_parser_create();...
|
by: Don HO |
last post by:
Hi,
I'm developing a project in C++ under MS Windows (without MFC).
I want to use an xml file as the configuration file of the program. The
problem is :
after downloading xerces, I realized...
|
by: Magnus Heino |
last post by:
Hi.
Are there any patterns or other design techniques that could be used
when implementing a xml parser that needs to be able to handle
different versions of a schema?
Let's say that I write...
|
by: Mike |
last post by:
Does anyone know of a minimal/mini/tiny/small xml parser
in c? I'm looking for something small that accepts a stream
or string, builds a c structure, and then returns an opaque
pointer to that...
|
by: Elmar Brandt |
last post by:
Hello,
we are looking for a fast XML parser.
The XML-files are very big (>2GB) and we want to convert them into other
formats via XSLT.
Has anyone an idea?
With best regards
Elmar Brandt
|
by: Harry |
last post by:
Hello,
I want to know if I can modify a xml-file with a xml-parser or can I
only read the information out of it.
If it is possible, I searching for xml-Parser for c++ (win32). I tried
with...
|
by: mahesh.kanakaraj |
last post by:
Hi Folks,
This is my first post to this group, and I really am not sure whether
this is the right group to ask my question. If its not an appropriate
question to this group, please correct me...
|
by: ChillyRoll |
last post by:
Hello guys,
I am looking for a parser in PHP that can return all the
attributes of XML entities. I know how to read the XML Entities, but I
have got a problem with reading attributes. So I will...
|
by: Eric Kaplan |
last post by:
anyone used the PUG XML parser?
http://trac.zeitherrschaft.org/zzub/browser/trunk/src/plugins/lunar/pugxml.h?rev=1561
Is it an easy XML parser to use?
any tutorial / sample code on how to...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
| |