Re: Fwd: [xmljs-users] Escaping " ' " in .getText();
Brought to you by:
djoham,
witchhunter
From: David J. <dj...@ya...> - 2003-11-22 03:13:29
|
Hi! If I'm reading your question right, I would just do the selectNode as you normally do. Once you get the result, check for null. If it is null, you know that the node wasn't there. Otherwise, you know it was and can continue as normal. Does that work? David --- Info <in...@be...> wrote: > Hey David, > I found that I had to "double escape" the apostrophes while calling the > CURL function from within my XML for SCRIPT JavaScript, like so: > > var escapedCamImage = unescapedCamImage.replace(/'/g, "\\'"); > > > And then it went through and saved my images! Building on the below, I > do have a question that you may be able to help me with. The way the > XML page I'm reading from is set up, is that if there is no Cover Art, > the XML tag isn't even written. Here's what it looks like if there is > Cover Art: > > >>> <coverart><![CDATA[/music/ > >>> %2fVolumes%2fAlexandria%20Project%2fMusic%20Library%2fArtists%2fAdams > >>> ,%2 > >>> 0Ryan%2f2001%20Gold%2f01-New%20York,%20New%20York.mp3/cover.jpg]]></ > >>> coverart> > > > And I can pull that path just fine, but if there is no Cover Art, the > XML output doesn't write an empty tag, like this: > > <coverart></coverart> > > > It simply doesn't write anything at all! So, when I run my XML for > SCRIPT, it complains that it can't find that tag (for all the right > reasons). How can I say: > > - Look for <coverart>xxxxx</coverart>, and if it's there, use XML for > SCRIPT to get it. And if it's not, don't bother looking (so I don't get > an error) > > > Any help would be great... I'm having trouble doing the if/else because > I don't know how to tell XML for SCRIPT to look for something that may > not be there at all. > > Thank you again, > Art > > > > > > > Begin forwarded message: > > > From: (Berklie) Info <in...@be...> > > Date: Thu Nov 20, 2003 6:09:49 PM America/Chicago > > To: David Joham <dj...@ya...> > > Subject: Re: [xmljs-users] Escaping " ' " in .getText(); > > > > 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,% > > 20Ryan%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... > === message truncated === __________________________________ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ |