Re: [xmljs-users] Escaping " ' " in .getText();
Brought to you by:
djoham,
witchhunter
From: David J. <dj...@ya...> - 2003-11-21 02:24:57
|
Sorry, I'm not going to be able to be much help on the Curl side :) The only thing I can think of is to do a regular expression search and replace for an apostropy and escape it with the "\" escape character in your file names and paths. The regular expression you would normally use to do something like this is: s/'/\/'/g which would turn all of the "'" characters into "\'". JavaScript does things a little differently. You will probably want to have code that looks similar to the following: var myAposString = "x'x'x"; var regEx = /\'/g; var myEscapedString = myAposString.replace(regEx, "\\'"); alert(myEscapedString); In this case, myEscapedString will be x\'x\'x From looking at your code below, I'm guessing that you would apply this regular expression to your coverArtInfo[0] variable. Doing so might make Curl happy - but that's just a guess... If you're still curious about what to do with the file I sent to you, here are all the steps you would need to see my example. 1) gunzip the file (If you're not a UNIX user, winzip will do this for you) 2) overwrite the existing domTagPathExample.html in xml_for_script-3.0/sampleApplications/classicDom/domSampleApplicationTagPath with the new file 3) load that file and hit the button. It performs a tagPath query and getText() on a node with a CDATA child that contains an apostropy. I hope this helps! Best regards, David --- Info <in...@be...> wrote: > Hi David, > I really, really, really want to thank you for getting back to me, but > I have no idea how to help you help me (and don't have a clue of what > to do with the file you sent). All I know is that I'm using "xmldom.js" > to parse XML data in order to get artwork displayed into one of my > Konfabulator (www.konfabulator.com) widgets. With this code: > > var currentCoverArtPath = "/player_status/current_song/song/coverart"; > var xmlFetchedCoverArt = xml.selectNode(currentCoverArtPath); > var fetchedCoverArt = xmlFetchedCoverArt.getText(); > > theCoverArt.src = "http://192.168.1.100:9000" + fetchedCoverArt; > > > I can get an image to show up if the CDATA does not contain an > apostrophe ('). For example: > > <coverart><![CDATA[/music/ > %2fVolumes%2fAlexandria%20Project%2fMusic%20Library%2fArtists%2fAdams,%2 > 0Ryan%2f2001%20Gold%2f01-New%20York,%20New%20York.mp3/cover.jpg]]></ > coverart> > > > But if the CDATA does contain an apostrophe, the program tells me: > > Failed to load image: Resources/Cache/cache.jpg (invalid image file) > > > Looking more closely though, it appears that it may be something else > (which I still wouldn't know how to fix). With the above data, a local > file is created using: > > coverArtInfo[0] = theCoverArt.src; > cacheFile = "Resources/Cache/cache.jpg"; > > var getImage = "curl --silent " + coverArtInfo[0] + " --max-time 300 -w > \"%{http_code}\\n\" --output " + cacheFile; > > > The cache file which is created ("Resources/Cache/cache.jpg") cannot be > opened by either Photoshop or anything else when there is an apostrophe > in the CDATA. So, apparently it isn't XML for SCRIPT... it's CURL > creating a bad file if there's an apostrophe in the CDATA. I suppose > I'll have to find some sort of CURL forum to ask about it, since I just > copied and pasted code and have no idea what those CURL commands above > do. > > Any ideas as to why CURL would mess up saving an image if it's web > address has an apostrophe? It's okay if you don't have time... you only > signed up for XML for SCRIPT help ;-). > > Thanks again, > Art > > > > > > > On Thursday, November 20, 2003, at 04:32 PM, David Joham wrote: > > > Hi! > > > > I'm not sure I'm seeing what you are describing. I just tried a quick > > derivation of the tagpath > > example application with some CDATA and an apostrophy and it seemed to > > work. Please see the > > attached gzipped example. You can load it by replacing > > domTagPathExample.html in: > > > > xml_for_script-3.0/sampleApplications/classicDom/ > > domSampleApplicationTagPath > > > > with the domTagPathExample.html I'm including with this message. > > > > When I load that example and hit the button, it comes back with what I > > would expect, which is the > > full string. Do you see something different? > > > > When you say it doesn't work, what exactly do you mean? Does the > > string get cut off or truncated > > at the position of the apostrophy when you call getText()? Or does the > > tagpath not work at all? > > > > Would it be possible to put together a quick recreation and send that > > to me. If you can, I can > > probably figure out what's going on pretty quick and get you going... > > > > Thanks > > > > David > > > > > > --- Info <in...@be...> wrote: > >> Hi there, > >> I'm using XML for SCRIPT in the following manner: > >> > >> var currentCoverArtPath = "/player_status/current_song/song/coverart"; > >> var xmlFetchedCoverArt = xml.selectNode(currentCoverArtPath); > >> var fetchedCoverArt = xmlFetchedCoverArt.getText(); > >> > >> if (fetchedCoverArt == "") { fetchedCoverArt = > >> "Resources/background.png"; } > >> else { theCoverArt.src = "http://192.168.1.100:9000" + > >> fetchedCoverArt; } > >> > >> > >> This works great to display album Cover Art when the string is > >> something like this: > >> > >> <coverart><![CDATA[/music/ > >> %2fVolumes%2fAlexandria%20Project%2fMusic%20Library%2fArtists%2fAdams, > >> %2 > >> 0Ryan%2f2001%20Gold%2f01-New%20York,%20New%20York.mp3/cover.jpg]]></ > >> coverart> > >> > >> > >> But if the string has a " ' " in it, like this (with the > >> "B-52's,%20The" or "1979%20The%20B-52's"): > >> > >> <coverart><![CDATA[/music/ > >> %2fVolumes%2fAlexandria%20Project%2fMusic%20Library%2fArtists%2fB- > >> 52's,%20The%2f1979%20The%20B-52's%2f01-Planet%20Claire.mp3/ > >> cover.jpg]]></coverart> > >> > >> > >> It doesn't work. Obviously (well I think anyway), it's because the " ' > >> " is causing the script to think the statement is over. How can I get > >> it to know that the " ' " is okay to have? I guess I'm trying to > >> figure > >> out how to "escape" it? > >> > >> Thanks, > >> BD > >> > >> > >> > >> ------------------------------------------------------- > >> This SF.net email is sponsored by: SF.net Giveback Program. > >> Does SourceForge.net help you be more productive? Does it > >> help you create better code? SHARE THE LOVE, and help us help > >> YOU! Click Here: http://sourceforge.net/donate/ > >> _______________________________________________ > >> xmljs-users mailing list > >> xml...@li... > >> https://lists.sourceforge.net/lists/listinfo/xmljs-users > > > > __________________________________ > > Do you Yahoo!? > > Free Pop-Up Blocker - Get it now > > http://companion.yahoo.com/<domTagPathExample.html.gz> > __________________________________ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ |