You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Thanos Chatziathanassiou <tc...@arx.gr> on 2004/03/18 21:06:04 UTC

Apache::ASP, $Response->write and XMLSubs

Hi there,

I was playing around with XMLSubs and I hit a problem.
First the basics:
httpd.conf
---snip---
PerlSetVar XMLSubsMatch mobile:[\w\-]+
PerlSetVar XMLSubsPerlArgs 0
PerlSetVar XMLSubsStrict 0
---snip---

code that works:
---snip---
if ($test) {
%>
<mobile:href href="home.xml?t=l" icon="images/wallpapers.gif">Some 
Custom Link</mobile:href>
<mobile:separator/>
<%
    }
%>
---snip---

and code that doesn't:
---snip---
if ($test) {
    $Response->write(qq{<mobile:href href="home.xml?t=l" 
icon="images/wallpapers.gif">Some Custom Link</mobile:href>
                        <mobile:separator/>});
}
---snip---
the latter dies and complains about ``Missing right curly or square 
bracket at...''
The strange part is that at that particular spot, my code has been 
peculiarly transformed:
---debug output---
if ($gcompatible) {
    $Response->write(qq{<% &mobile::href({ 'icon' => 
'images/wallpapers.gif', 'href' => 'home.xml?t=l' }, 'Some Custom 
Link'); ;                 &Apache::ASP::WriteRef($main::Response, 
\('<mobile:separator/>});
}
---debug output---

No doubt I'm doing something wrong, but I hate jumping in and out of 
code in conditionals and loops, so I'm wondering what is it that I'm 
missing.

Can anyone enlighten me please ?
Thanks in advance.

Thanos Chatziathanassiou


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Apache::ASP, $Response->write and XMLSubs

Posted by Thanos Chatziathanassiou <tc...@arx.gr>.
Josh Chamas wrote:

> As the name XMLSubs implies, the XML tags in particular are transformed
> into perl subroutines during compilation.  So trying to 
> $Response->Write()
> those tags will not work.  $Response->Write is for direct output, but
> XMLSubs need to be executed as code.  If you want to execute XMLSubs
> dynamically after building up the string text, then you will have to
> build up the text string on the fly, and then dynamically execute
> an include scalar ref like:
>
>   my $execute_tag = '<mobile\:href href="home.xml?t=l">Custom 
> Link</mobile\:href>';
>   $Response->Include(\$execute_tag);
>
> Notice the backslashes to make sure the compiler does not try to 
> compile the tag
> before the script executes.
>
> In this case though, it is probably better if you did:
>
>  <% if($gcompatible) { %>
>     <mobile:href href="home.xml?t=l">Custom Link</mobile:href>
>  <% } else { %>
>      ...
>  <% } %>
>
> If what you really want is to build up XML during script processing
> for later transformation, I would recommend you look into using the
> XSLT methods for this, which does the XML transformation during the 
> output stage,
> after $Response->Write() is done.

You're right, XSLT will do better for me in this case.
I was actually impressed at how far the parser got and "almost" but not 
quite made it.
I mean, this understandably works:
$Response->write(&mobile::href({ 'icon' => 'images/wallpapers.gif', 
'href' => 'home.xml?t=l' }, 'Some Custom Link'));
although it also prints an extra 1, which is the include's return value. 
So if I either ommit the $Response->write or modify the Include so that 
it returns "", it's ok.
And the whole idea is if it would be possible for the XMLSub to escape 
itself (I know I'm oversimplifying here) as it gets expanded from tag to 
sub-routine.
Once again, I'm not that familiar with the internals of Apache::ASP to 
know how feasible this is, it just felt kind of natural from the web 
developer's point of view.

Regards,
Thanos Chatziathanassiou



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Apache::ASP, $Response->write and XMLSubs

Posted by Josh Chamas <jo...@chamas.com>.
Thanos Chatziathanassiou wrote:
...
> ---snip---
> if ($test) {
>    $Response->write(qq{<mobile:href href="home.xml?t=l" 
> icon="images/wallpapers.gif">Some Custom Link</mobile:href>
>                        <mobile:separator/>});
> }
> ---snip---
> the latter dies and complains about ``Missing right curly or square 
> bracket at...''
> The strange part is that at that particular spot, my code has been 
> peculiarly transformed:
> ---debug output---
> if ($gcompatible) {
>    $Response->write(qq{<% &mobile::href({ 'icon' => 
> 'images/wallpapers.gif', 'href' => 'home.xml?t=l' }, 'Some Custom 
> Link'); ;                 &Apache::ASP::WriteRef($main::Response, 
> \('<mobile:separator/>});
> }

As the name XMLSubs implies, the XML tags in particular are transformed
into perl subroutines during compilation.  So trying to $Response->Write()
those tags will not work.  $Response->Write is for direct output, but
XMLSubs need to be executed as code.  If you want to execute XMLSubs
dynamically after building up the string text, then you will have to
build up the text string on the fly, and then dynamically execute
an include scalar ref like:

   my $execute_tag = '<mobile\:href href="home.xml?t=l">Custom Link</mobile\:href>';
   $Response->Include(\$execute_tag);

Notice the backslashes to make sure the compiler does not try to compile the tag
before the script executes.

In this case though, it is probably better if you did:

  <% if($gcompatible) { %>
     <mobile:href href="home.xml?t=l">Custom Link</mobile:href>
  <% } else { %>
      ...
  <% } %>

If what you really want is to build up XML during script processing
for later transformation, I would recommend you look into using the
XSLT methods for this, which does the XML transformation during the output stage,
after $Response->Write() is done.

Regards,

Josh

________________________________________________________________________
Josh Chamas, Founder    | NodeWorks - http://www.nodeworks.com
Chamas Enterprises Inc. | NodeWorks Directory - http://dir.nodeworks.com
http://www.chamas.com   | Apache::ASP - http://www.apache-asp.org



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org