You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Pizzo <ch...@artinside.com> on 2002/10/31 23:38:37 UTC

Novice - Problem with data encoding

Hi,
I have an XML doc that I generated using XML::LibXML that needs to be
included as a hidden form field in a form post.

Code snippet:

sub getcXML   {
use XML::LibXML;
my $resp_doc = XML::LibXML::Document->new();
my $root = $resp_doc->createElement('blah');
...
my $content = $resp_doc->toString;
return $content
}

The html is:
<form name="sndxml" method = "post" action =
http://someserver.com/process_xml>
    <input type = "hidden" name = "xml_here" value = "[+ getcXML(); +]">
    <input type = "submit" value = "Order">
</form>



The problem is that the browser is encoding the XML doc.

ie.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gtfd SYSTEM "http://gftd/schemas/data.dtd">

turns into:
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;DOCTYPE gtfd SYSTEM &quot;http://gftd/schemas/data.dtd&quot;&gt;

which blows up in the parsing.  If I edit the result and swap back the < >
and " it works.
How can I prevent the encoding of the XML data?


Anyone point me in the right direction?

Thanks,
Chris


Re: Novice - Problem with data encoding

Posted by Gerald Richter <ri...@ecos.de>.

> Thats what is wierd.  I don't do any escaping.  I think it might be
embperl
> doing the escaping because if I do a print of the XML doc string it has no
> escaping.  If I put the string between [+ $content +] then it gets
escaped.
>

Yes, Embperl escapes your output per default, you can turn it off by using
$escmode e.g.

[+ do { local $escmode = 0 ; $content } +]

Gerald

P.S. The do { } is only necessary in Embperl 2.0

-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------




Re: Novice - Problem with data encoding

Posted by Chris Pizzo <ch...@artinside.com>.
Thats what is wierd.  I don't do any escaping.  I think it might be embperl
doing the escaping because if I do a print of the XML doc string it has no
escaping.  If I put the string between [+ $content +] then it gets escaped.

Thanks for your help,
Chris
----- Original Message -----
From: "Antti Haapala" <an...@iki.fi>
To: "Chris Pizzo" <ch...@artinside.com>
Cc: <mo...@perl.apache.org>
Sent: Friday, November 01, 2002 6:35 AM
Subject: Re: Novice - Problem with data encoding


>
> > I have an XML doc that I generated using XML::LibXML that needs to be
> > included as a hidden form field in a form post.
> >
> > The problem is that the browser is encoding the XML doc.
> >
> > ie.
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE gtfd SYSTEM "http://gftd/schemas/data.dtd">
> >
> > turns into:
> > &lt;?xml version="1.0" encoding="UTF-8"?&gt;
> > &lt;DOCTYPE gtfd SYSTEM &quot;http://gftd/schemas/data.dtd&quot;&gt;
> >
> > which blows up in the parsing.  If I edit the result and swap back the <
> > and " it works. How can I prevent the encoding of the XML data?
>
> You have probably escaped the xml snippet twice yourself - check the code
> of the page from your browser. If you see the value of your hidden field
> as "&amp;lt;?xml...", you have done double escaping.
>
> Just remove one of the escaping passes and it should work.
>
> The browser isn't supposed to do any such encoding on its own. If it does
> you need to change your browser. You aren't using Netscape 4.0, are you?
>
> --
> Antti Haapala
>
>


Re: Novice - Problem with data encoding

Posted by Antti Haapala <an...@iki.fi>.
> I have an XML doc that I generated using XML::LibXML that needs to be
> included as a hidden form field in a form post.
>
> The problem is that the browser is encoding the XML doc.
>
> ie.
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE gtfd SYSTEM "http://gftd/schemas/data.dtd">
>
> turns into:
> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
> &lt;DOCTYPE gtfd SYSTEM &quot;http://gftd/schemas/data.dtd&quot;&gt;
>
> which blows up in the parsing.  If I edit the result and swap back the <
> and " it works. How can I prevent the encoding of the XML data?

You have probably escaped the xml snippet twice yourself - check the code
of the page from your browser. If you see the value of your hidden field
as "&amp;lt;?xml...", you have done double escaping.

Just remove one of the escaping passes and it should work.

The browser isn't supposed to do any such encoding on its own. If it does
you need to change your browser. You aren't using Netscape 4.0, are you?

-- 
Antti Haapala