cURL and unicode? text problem

Hello again,

This problem might be a bit offtopic. I hope someone still can help.

I am using AppleScript to envoke cURL using do shell script.
Unfortunately the resulted xml includes some unwanted characters.

See for yourself:

do shell script "curl -d method=event.search -G -d api_key=0ccd79f5e6 -d search_text=Arcade_Fire -d metro_id=11 " & quoted form of "http://upcoming.org/services/rest/"

1.) I guess the problems lies within cURL and there might be a way to tell cURL how to format it’s output, but i looket into cURLs man page and could’t find any relevant commands

2.) Maybe it’s possible to convert the result so it is displayed correctly using AppleScript.
I tried using as unicode text and ended up with chinese text…

Any tipps?

Greetings
research

What are the unwanted characters?

Well, I’m sure there’s a better name for them…

By example &(the old end, like i would call it) ends up being &
a quote character ends up being " and an ’ ends up being '.

I’m really bad at naming characters!

I thought so. That’s expected behavior for XML; ampersands, quotes, angled brackets (< and >), and other characters can have special meanings, so they are encoded (otherwise, it wouldn’t be valid XML).

The trick now is figuring out the best way to decode them.

by decoding them you mean, writing handlers that replace a certain character with another?

there’s the replace_chars subroutine from apples essential subroutines http://www.apple.com/applescript/guidebook/sbrt/index.html
which could do the replacing.

on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars

so one only has to find out which xml specific string is connected to which character.
i’m gonna take a look at that!

thanks for the answers!

so, i guess, this was not a unicode problem right?

By the way, it’s not easy to search for posts concerning XML when search keywords with less than 4 characters are being ignored…

so, i came up with this nearly perfect working subroutine:

set myXML to "It's working quite & well, except for the "quotes"!"

decode_XML(myXML)

on decode_XML(this_text)
	set search_strings to {"&", """, "'", "<", ">"}
	set replacement_strings to {"&", "\"", "'", "<", ">"}
	repeat with i from 1 to (count of search_strings)
		set search_string to item i of search_strings
		set replacement_string to item i of replacement_strings
		if this_text contains search_string then
			set AppleScript's text item delimiters to search_string
			set the item_list to every text item of this_text
			set AppleScript's text item delimiters to replacement_string
			set this_text to the item_list as string
			set AppleScript's text item delimiters to ""
		end if
	end repeat
	return this_text
end decode_XML

It’s working fine, except for the quotes!

It’s how the SQL search works, sorry.

What’s wrong with the quotes?

the quotes are displayed like this "

That’s because AppleScript escapes quotes when they’re are displayed; the actual text won’t contain those slashes.

You are right, when displaying a dialog the quotes are displayed perfectly right.
I didn’t know that AppleScript escapes quotes in the result window…
Sorry!

Thanks for the help again!