Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 09-16-2008, 01:48 AM
kos's Avatar
kos kos is offline
Coding Tiger
 
Join Date: 04-13-07
Location: .ro
Posts: 4,029
iTrader: 3 / 100%
yet another RegExp problem

This is what I have at this point:
Code:
<Content> <![CDATA[ (function() {alert('done');})(); ]]> </Content>
this is the content of an XML file I request using ajax. I want to execute the function inside Content section and I can do that just fine when the javascript block is not inside the CDATA comment.

I was wondering if anyone can help with a RegExp to help me extract the js block from the CDATA comment (or to just remove the CDATA comment and return the js block).

please
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 09-22-2008, 01:36 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
Do you want a JS regexp? Or are you planning to do the extraction thing in any other language?
 
Reply With Quote
  #3  
Old 09-22-2008, 06:10 AM
marc_gfx marc_gfx is offline
Contributing Member
 
Join Date: 07-01-06
Posts: 126
iTrader: 0 / 0%
/\((.*?)\)\;/

($1);

maybe?
 
Reply With Quote
  #4  
Old 09-22-2008, 06:38 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
Quote:
Originally Posted by marc_gfx View Post
/\((.*?)\)\;/

($1);

maybe?
No, this will match anything between ( and );
So in this case $1 will be "function() {alert('done'"
 
Reply With Quote
  #5  
Old 09-22-2008, 06:43 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
I'd go for
/<!\[CDATA\[(.*)\]\]>/si
 
Reply With Quote
  #6  
Old 09-22-2008, 08:00 AM
kos's Avatar
kos kos is offline
Coding Tiger
 
Join Date: 04-13-07
Location: .ro
Posts: 4,029
iTrader: 3 / 100%
Quote:
Originally Posted by nasty.web View Post
Do you want a JS regexp? Or are you planning to do the extraction thing in any other language?
I first planned for a JS regexp (but I won't say no for a php one though )

the thing I'm interested in is the content inside the CDATA comment; that's what I need.

though, I've found a way of doing it without the use of a regexp but it's kinda weird because when I navigate through the xml tree, in IE I have to use childNodes[0].data to get the data from the CDATA while in Firefox the childNodes[1].data

So I thought that a regexp would be nice to have..
 
Reply With Quote
  #7  
Old 09-22-2008, 08:12 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
Code:
<script type="text/javascript"> var content = "<Content><![CDATA[(function() {alert('done');})();]]></Content>"; var script = content.replace(/<!\[CDATA\[(.*?)\]\]>/gi,"$1"); document.writeln(script); // eval </script>
HTH
 
Reply With Quote
  #8  
Old 09-22-2008, 08:15 AM
kos's Avatar
kos kos is offline
Coding Tiger
 
Join Date: 04-13-07
Location: .ro
Posts: 4,029
iTrader: 3 / 100%
thank you man, you're beautiful!
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google's China Problem (and China's Google Problem) - NYTimes Sunday Mag (4/23/06) Julie Google Forum 4 10-26-2009 02:54 PM
Problem with text looking funky on windows… maybe an anti aliasing problem? jpf566 Web Design Lobby 2 07-09-2008 06:40 AM
Need help with RegExp kos Coding Forum 9 04-23-2007 09:45 PM
regexp implementation help (vbscript) grobar Coding Forum 0 08-13-2006 11:55 AM
Javascript: Dynmically change match criteria in RegExp?? Once Coding Forum 0 06-03-2004 01:16 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:28 AM.
Powered by vBulletin
Copyright © 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC