Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

problem with quotes

Posted on 2003-10-29
3
Medium Priority
?
150 Views
Last Modified: 2010-03-05
I've got some code that pulls data from an xml database and loads it into a request form for users. Works great in most cases, but I run intro trouble if any of the data I'm pulling has quotes in it. Only happens with article titles, but it DOES happen. Here's a code snippet:

use LWP::Simple;
$xml = get $queryStr;
use XML::LibXML;

my $p = XML::LibXML->new;
my $root = $p->parse_string($xml);
 
foreach my $rec ($root->findnodes('/inm:Results/inm:Recordset/*')) {
 local $" = ', ';
 my @authors = map { $_->to_literal } $rec->findnodes('inm:AUTHORS/text()');
 print $ContentType;
 print $Head;
 print "<table><tr><td width=80 valign=top><b>Reference: </b></td><td width=600>@authors: <INPUT NAME=AUTHORS TYPE=hidden VALUE=\"@authors\">";
 
  if ($rec->findvalue('inm:TITLE/text()')){ print $rec->findvalue('inm:TITLE/text()'), ". <INPUT NAME=TITLE TYPE=hidden VALUE=\"", $rec->findvalue('inm:TITLE/text()'),"\">"};
 
  print "<tr><td></td><td></td></tr>\n</table>\n";
}

Specifically, here's where I run into trouble once in a while:

<INPUT NAME=TITLE TYPE=hidden VALUE=\"", $rec->findvalue('inm:TITLE/text()'),"\">"

The TITLE field value gets truncated if the title data I'm pulling has any quotes in it. Can't use single quotes instead because they're a bit more common (in my titles) than the double quotes.

Please advise.

Thanks,

Timothy
0
Comment
Question by:GessWurker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 2000 total points
ID: 9647526
On this line:

if ($rec->findvalue('inm:TITLE/text()')){ print $rec->findvalue('inm:TITLE/text()'), ". <INPUT NAME=TITLE TYPE=hidden VALUE=\"", $rec->findvalue('inm:TITLE/text()'),"\">"};
 
Try doing it like this, instead:

if(  my $title = $rec->findvalue('inm:TITLE/text()')) {
        print $title,
             ". <INPUT NAME=TITLE TYPE=hidden VALUE=\",
             uri_escape( $title),
             "\">"
       };

You'll probably find you need to add a line:

use URI::Escape qw(uri_escape);

at the top of your script.

What this does is encode the double quote as %22 so that it is not misinterpreted as ending the VALUE= attribute.

0
 
LVL 8

Expert Comment

by:harris_c
ID: 9647959
remove the quotes first ?
$tmp = $rec->findvalue('inm:TITLE/text()') =~ s/'//g;

hec",)
0
 

Author Comment

by:GessWurker
ID: 9651614
jmcg:

Perfect! Thanks. I'll be using this a lot!

--Timothy
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question