C
citius21j
I would be obliged if you could guide me through this task.
I have several XML output files that I need to parse through perl to
read the data. I am using the XML:
arser module but the problem is
that my script (see below) for the following XML gives output as
******************************************************************************************************
XML
**************************************************************************************************
- <principal_info customer_xref_id="HCuddebacke19370666"
relative_CB_num="01">
<CB_format_name>Cuddebacke, Harry</CB_format_name>
<SSN>444000666</SSN>
- <current_address>
<address>90345 Phocis Rd.</address>
<city>Powell</city>
<state>OH</state>
<zip>43065</zip>
**************************************************************************************************
OUTPUT
***************************************************************************************************
customer_xref_id=HCuddebacke19370666
relative_CB_num=01
Cuddebacke, Harry 444000666 90345 Phocis Rd. Powell OH 43065
How could I modify it to instead show
customer_xref_id=HCuddebacke19370666
relative_CB_num=01
CB_format_name=Cuddebacke, Harry
SSN=444000666
address=90345 Phocis Rd.
city=Powell
state=OH
zip=43065
****************************************************************************************************
Script is as follows
***************************************************************************************************
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw
cgi);
# ---------------------------------------------
my $req = new CGI;
print $req->header();
use XML:
arser;
my $file = "output2.xml";
my $parser = new XML:
arser(ErrorContext => 2);
$parser->setHandlers(Start => \&start_handler,
End => \&end_handler,
Char => \&char_handler);
$parser->parsefile($file);
# ---------------------------------------------
#
# The handlers for the XML Parser.
#
sub start_handler
{
my $expat = shift; my $element = shift;
# element is the name of the tag
# Handle the attributes
while (@_) {
my $att = shift;
my $val = shift;
i f($element eq "SOAP:Envelope"){
$att="";
$val="";
}
else{
print "$att=$val <br>";}
}
}
sub end_handler
{
my $expat = shift; my $element = shift;
print "\n\n";
}
sub char_handler
{
my ($p, $data) = @_;
print $data;
}******************************************************************************************************
I am looking forward to your help and am sorry to bother you in this
regard. Thanking you for your time. Kindly reply at your earliest
convenience.
I have several XML output files that I need to parse through perl to
read the data. I am using the XML:
that my script (see below) for the following XML gives output as
******************************************************************************************************
XML
**************************************************************************************************
- <principal_info customer_xref_id="HCuddebacke19370666"
relative_CB_num="01">
<CB_format_name>Cuddebacke, Harry</CB_format_name>
<SSN>444000666</SSN>
- <current_address>
<address>90345 Phocis Rd.</address>
<city>Powell</city>
<state>OH</state>
<zip>43065</zip>
**************************************************************************************************
OUTPUT
***************************************************************************************************
customer_xref_id=HCuddebacke19370666
relative_CB_num=01
Cuddebacke, Harry 444000666 90345 Phocis Rd. Powell OH 43065
How could I modify it to instead show
customer_xref_id=HCuddebacke19370666
relative_CB_num=01
CB_format_name=Cuddebacke, Harry
SSN=444000666
address=90345 Phocis Rd.
city=Powell
state=OH
zip=43065
****************************************************************************************************
Script is as follows
***************************************************************************************************
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw
# ---------------------------------------------
my $req = new CGI;
print $req->header();
use XML:
my $file = "output2.xml";
my $parser = new XML:
$parser->setHandlers(Start => \&start_handler,
End => \&end_handler,
Char => \&char_handler);
$parser->parsefile($file);
# ---------------------------------------------
#
# The handlers for the XML Parser.
#
sub start_handler
{
my $expat = shift; my $element = shift;
# element is the name of the tag
# Handle the attributes
while (@_) {
my $att = shift;
my $val = shift;
i f($element eq "SOAP:Envelope"){
$att="";
$val="";
}
else{
print "$att=$val <br>";}
}
}
sub end_handler
{
my $expat = shift; my $element = shift;
print "\n\n";
}
sub char_handler
{
my ($p, $data) = @_;
print $data;
}******************************************************************************************************
I am looking forward to your help and am sorry to bother you in this
regard. Thanking you for your time. Kindly reply at your earliest
convenience.