[ic] IC/eBay API integration -> impending donation
Grant
listbox at email.com
Mon Sep 15 13:11:33 EDT 2003
> > So, if anyone can help me with the three things I'm stuck on I'd greatly
> > appreciate it. Here they are:
>
> Perhaps some quickie-advice will help...
>
> > 1. nested subs in a UserTag
>
> Is it that important that they be nested?
>
>
> Usertag bob Routine <<EOR
>
> sub a
> {
> return "a";
> }
>
> sub
> {
> return a();
> }
> EOR
I've rearranged the parsexml UserTag and now the only errors I get at
restart say 'Variable "$tag" will not stay shared' at lines referring to
where the $tag variable is located in the DefaultHandler sub. It sounds
like there must be a simple solution, but I just don't know enough about
Perl to find it. Here's the rearranged tag:
###
Usertag parsexml hasEndTag
Usertag parsexml Interpolate 1
Usertag parsexml Routine <<EOR
sub Start_Handler {
my $p=shift;
my $el=shift;
$tag=$el;
while (my $key=shift) {
my $val=shift;
}
}
sub End_Handler {
my $p=shift;
my $el=shift;
}
sub Default_Handler {
my $p=shift;
my $el=shift;
if (($el eq "")||($tag eq "")) {
return;
}
if ($tag eq "XMLDOC_WRAPPER") {
return;
}
$CGI->{$tag}=$el;
$result.=$tag."=".$el."\n";
push @field,$tag;$tag="";
}
sub cleanupxml {
my ($xmltoclean)=@_;
my $cleanedxml="";
my $returnxml="";
my $start="";
my $line="";
my $x=substr($xmltoclean,1,6);
if (index($xmltoclean,"\<\?xml")<0) {
$cleanedxml="<\?xml version=\"1.0\" encoding=\"UTF-8\"\?\>"
."\n"
# ."\<temp\>".$x."\<\/temp\>" # for debugging
.$xmltoclean;
} else {
$cleanedxml=substr($xmltoclean,index($xmltoclean,"\<\?xml"));
}
my @xmllines=split("\n",$cleanedxml);
foreach $line (@xmllines) {
next if (($line eq "")||($line eq "\n")||($line eq
"\r")||($line eq " "));
if ($start ne "") {
$returnxml.=$line."\n";
next;
}
next if lc(substr($line,0,5)) ne "\<\?xml";
$returnxml.=$line."\n\<XMLDOC_WRAPPER\>\n";
$start="x";
}
if ($returnxml eq "") {
return $returnxml
."\<\?xml
version=\"1.0\"encoding=\"UTF\-8\"?>\n\<XMLDOC_WRAPPER\>\<\/XMLDOC_WRAPPER\>
";
}
return $returnxml."\<\/XMLDOC_WRAPPER\>";
}
sub {
my ($xml)=@_;
require XML::Parser;
my @field=();
my $tag="";
my $result="";
my $parser=new XML::Parser(ErrorContext=>2);
$parser->setHandlers(
Start=>\&Start_Handler,
End =>\&End_Handler,
Default=>\&Default_Handler
);
# $result.="--cleanup--<br>\n"; # for debugging
my $cleanxml=cleanupxml($xml);
# return $cleanxml; # Preliminary exit for debugging purposes
# $result.="cleanxml=<br>\n".$cleanxml."<br>\n"; # for debugging
my $parseresult=$parser->parse($cleanxml);
my $fieldname="";
# $result.=substr($cleanxml,1,8); # for debugging
foreach $fieldname (@field) {
next if $fieldname eq "";
next if $fieldname eq "XMLDOC_WRAPPER";
$result.=$fieldname.'='.$CGI->{$fieldname}."\n";
}
return $result;
}
EOR
###
- Grant
More information about the interchange-users
mailing list