For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > January 2006 > Problem parsing xml link with _GET parameters.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem parsing xml link with _GET parameters.
Tony

2006-01-09, 10:21 pm

I tried using the following to produce xml output like the
hypothetical example...

<?php
echo '<link>www.domain.com/index.php?A=3D1&B=3D2&C=3D3</link>';
?>

but I found I had to substitute HTML character code like the
following to prevent xml errors...

<?php
echo '<link>www.domain.com/index.php?A#61;1&B=2&C=3</link>'=
;
?>

Once that was accomplished I then tried to parse the above xml line with Sm=
arty.
I expected something like...

<a href=3D"http://www.domain.com/index.php?A=3D1&B=3D2&C=3D3">LINK</a>


However, when Smarty parses the file, the output is:

<a href=3D"http://www.domain.com/index.php?A">LINK</a>
<a href=3D"http://=3D">LINK</a>
<a href=3D"http://1">LINK</a>
<a href=3D"http://&">LINK</a>
<a href=3D"http://B">LINK</a>
<a href=3D"http://=3D">LINK</a>
<a href=3D"http://2">LINK</a>
<a href=3D"http://&">LINK</a>
<a href=3D"http://C">LINK</a>
<a href=3D"http://=3D">LINK</a>
<a href=3D"http://3">LINK</a>

Smarty Parsing Functions:

function startContact($parser, $name, $attribs){
global $currentTag, $currentAttribs, $contact, $page;
$currentTag =3D $name;
$currentAttribs =3D $attribs;
switch ($name) {
case "link";
$contact .=3D "";
break;
}
return $contact;
}

function endContact($parser, $name){
global $currentTag, $contact, $page;
switch ($name) {
case "link";
$contact .=3D "";
break;
}
$currentTag =3D "";
$currentAttribs =3D "";
return $contact;
}

function dataContact($parser, $data){
global $currentTag, $contact, $page;
switch ($currentTag) {
case "link";
$contact .=3D "<a href=3D\"http://".$data."\">LINK</a>";
break;
}
return $contact;
}

Has anyone experienced this problem? How should I correct for it?
Tony

2006-01-12, 7:07 pm

Thanks! That fixed the problem.

On 1/12/06, Alexander Valyalkin <valyala@gmail.com> wrote:
> It seems business logic of your script is broken. Try this:
>
> function startContact($parser, $name, $attribs){
> global $currentTag, $currentAttribs, $contact, $page;
> $currentTag =3D $name;
> $currentAttribs =3D $attribs;
> switch ($name) {
> case "link";
> $contact =3D "<a href=3D\"http://";
> break;
> }
> return $contact;
> }
>
> function endContact($parser, $name){
> global $currentTag, $contact, $page;
> switch ($name) {
> case "link";
> $contact .=3D "\">LINK</a>";
> break;
> }
> $currentTag =3D "";
> $currentAttribs =3D "";
> return $contact;
> }
>
> function dataContact($parser, $data){
> global $currentTag, $contact, $page;
> switch ($currentTag) {
> case "link";
> $contact .=3D htmlspecialchars($data);
> break;
> }
> return $contact;
> }
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com