Shawn Wowk wrote:
> 
> Hi,
> 
> I am posting this to the Web list and XML list as I think this issue crosses
> the boundary of both.
> 
> I have started to poke around with XML/XSL and noticed something strange. I
> am using CGI to dynamically generate XML from a database. I have a
> stylesheet to to transform this XML, render it and create a HTML FORM that
> accepts inputs. These input parameters then get passed to the original CGI
> script, the information gets added to the database and the XML is generated
> again. (Essentially I am adding a child element.)
> 
> What I have found is the last (in the form) parameter value has an invisible
> character in it.
> 
> For instance: My form has this
> <FORM METHOD="POST">
> <INPUT TYPE="TEXT" NAME="form_input_1">
> <INPUT TYPE="TEXT" NAME="form_input_2">
> <INPUT TYPE="TEXT" NAME="form_input_3">
> <INPUT TYPE="TEXT" NAME="form_input_4">
> <INPUT TYPE="TEXT" NAME="form_input_5">
> <INPUT TYPE="SUBMIT">
> </FORM>
> 
> I grab the passed parameters
> $query->param("form_input_1");
> $query->param("form_input_2");
> $query->param("form_input_3");
> $query->param("form_input_4");
> $query->param("form_input_5");
> These are then passed into the database.
> 
> When I then grab the database entries and output them to XML
> <foo>
>  <foo1>$form_input_1</foo1>
>  <foo2>$form_input_2</foo2>
>  <foo3>$form_input_3</foo3>
>  <foo4>$form_input_4</foo4>
>  <foo5>$form_input_5</foo5>
> </foo>
> 
> However IE reports "An invalid character was found in text content. Line 1,
> Position ..."
> <foo><foo1>$form_input_1</foo1><foo2>$form_input_2</foo2><foo3>$form_input_3
> </foo3><foo4>$form_input_4</foo4><foo5>$form_input_5
> 
> Now if I chop($form_input_5) before adding to the database or after I have
> retrieved it from the it works fine because it removes the character
> (whatever it is). Problem with this is it that it assumes that form_input_5
> is always going to be the last parameter in the form which is not always the
> case. For instance if the form has the 4 and 5 inputs reversed then the
> character exists at the end of '<foo4>$form_input_4'.
> 
> I am assuming that this is not a problem generally as HTML is fault
> tolerant, whereas XML is not.
> 
> Now I know there are a couple of work arounds to this, like passing another
> blank parameter at the end of my form. Or 'chop'ping the last parameter
> passed. However, I would rather not do that, as I do not really want to keep
> track of the order I am passing parameters.
> 
> Is there away of choping the character off of the parameter string before
> collecting the parameter values?
> 
> Is this a bug?

Maybe one you created. :)

You need to do first things first.  Dump the data so you know what the character is.
Here's my dump routine (if you dump to the browser, make sure you get your 
content-type header out first.):

sub dumpit {    # &dumpit (<var>[, *FH]);
        my $buf = shift;
        my $fh = *STDERR;
        $fh = shift if @_;
        my ($len, $ii, $jj);

for ($ii = 0; $ii < length ($buf); $ii += 16) {

        printf $fh "%04x  ", $ii;
        $len = length ($buf) - $ii;
        $len = 16 if $len > 16;

        my $buffer = substr ($buf, $ii, 16); 
        print $fh map { sprintf "%02x ", $_; } unpack 'C8', $buffer;
        print $fh ' ';
        print $fh map { sprintf "%02x ", $_; } unpack 'C*', 
          substr ($buffer, 8, 8) if length $buffer > 8;
        print $fh '  ' . '   ' x (16 - $len);

        for ($jj = 0; $jj < $len; $jj++) {

                my $ch = substr $buffer, $jj, 1;
                if ((ord $ch) >= 32 && (ord $ch) < 0x7f) {
                        print $fh $ch;
                } else {
                        print $fh '.';
                }
        }
        print $fh "\n";
}

}

There may be embedded \r's and \n's in your input - depending on how 
you input the data.  I would use a RE to remove all crap (front/back) 
of my parameters:

        s/^\s*//;
        s/\s*$//;

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.todbe.com/
  / ) /--<  o // //      Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to