Fields containing inverted commas

Post Reply
gcorbin
Posts: 62
Joined: 21 Aug 06 12:31
Location: Brisbane

Fields containing inverted commas

Post by gcorbin » 03 Nov 20 14:20

I use this code for one line of my Custom Thumb Info to display the Darwin Core scientific name if it exists, else the vernacular name if it exists, else the headline. This normally works well .

Code: Select all

%code result := iif(length('%xmp:dwc:Taxon.dwc:scientificName')>0, '%xmp:dwc:Taxon.dwc:scientificName'{encode=html}, iif(length('%xmp:dwc:Taxon.dwc:vernacularName')>0, '%xmp:dwc:Taxon.dwc:vernacularName'{encode=html}, '%xmp:photoshop:Headline'{encode=html})) %/code
Unfortunately, if any of the referenced fields contains an inverted comma, such as
Granny's Cloak Moth
my code gives the error
Syntax error. Source position: 1,106
I cannot work out the correct way to handle strings containing inverted commas. Anyone know how to do this?

User avatar
G8DHE
Posts: 246
Joined: 21 Aug 17 13:58

Re: Fields containing inverted commas

Post by G8DHE » 03 Nov 20 15:01

Just a guess, can you use a double quote " as opposed to a single quote ' in those positions ?
Geoff Mather (G8DHE)

Hert
Posts: 6435
Joined: 13 Sep 03 7:24

Re: Fields containing inverted commas

Post by Hert » 03 Nov 20 15:04

Try the QUOTES encoding instead of HTML encoding

Code: Select all

%code result := iif(length('%xmp:dwc:Taxon.dwc:scientificName{encode=quotes}')>0, '%xmp:dwc:Taxon.dwc:scientificName'{encode=quotes}, iif(length('%xmp:dwc:Taxon.dwc:vernacularName{encode=quotes}')>0, '%xmp:dwc:Taxon.dwc:vernacularName'{encode=quotes}, '%xmp:photoshop:Headline'{encode=quotes})) %/code
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

gcorbin
Posts: 62
Joined: 21 Aug 06 12:31
Location: Brisbane

Re: Fields containing inverted commas

Post by gcorbin » 03 Nov 20 22:27

Thanks G8DHE, but I already tried double quotes without success. I also tried using StringReplace to replace the single quote with two quotes, but the error occurs before the StringReplace runs, so this doesn't work.

Hert, unfortunately, your QUOTES code doesn't overcome the issue. The error is the same.

To reproduce, paste your code (or my code) into a Custom Thumb Info line and enter the string xx'yy into the HeadLine field. If you enter xx''yy into the HeadLine field, the custom thumb info will display xx'yy so the issue is just how to correctly handle a sting containing quotes in the code.

I suspect the solution will be to reference the XMP values without enclosing in quotes. Is there a way to do this? eg. something like XMPValue('dwc:Taxon.dwc:scientificName') rather than '%xmp:dwc:Taxon.dwc:scientificName{encode=quotes}'.

fbungarz
Posts: 1594
Joined: 08 Dec 06 5:03
Location: Arizona, USA

Re: Fields containing inverted commas

Post by fbungarz » 04 Nov 20 0:23

Hi gcorbin,
this is great, somebody else using the DarwinCore !!!
Happy to see this. Sorry tough that I don't have an idea how to resolve the issue with the quotes...
Cheers,
Frank

Hert
Posts: 6435
Joined: 13 Sep 03 7:24

Re: Fields containing inverted commas

Post by Hert » 05 Nov 20 11:19

The quotes encoding works fine here. But looking at your posted line, I noticed that you have the {encode=html} marker behind the single quote but that should be directly after the macro command.

Here's the corrected one:

Code: Select all

%code result := iif(length('%xmp:dwc:Taxon.dwc:scientificName{encode=quotes}')>0, '%xmp:dwc:Taxon.dwc:scientificName{encode=quotes}', iif(length('%xmp:dwc:Taxon.dwc:vernacularName{encode=quotes}')>0, '%xmp:dwc:Taxon.dwc:vernacularName{encode=quotes}', '%xmp:photoshop:Headline{encode=quotes}')) %/code
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

gcorbin
Posts: 62
Joined: 21 Aug 06 12:31
Location: Brisbane

Re: Fields containing inverted commas

Post by gcorbin » 07 Nov 20 1:19

Thanks Hert. Good find which I missed. Everything works as expected now.

Thanks for your help.

Post Reply