Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove <![CDATA[]]>

Status
Not open for further replies.

cadbilbao

Programmer
Joined
Apr 9, 2001
Messages
233
Location
ES
I'm trying to parse an XML document, but I get always:
<![CDATA[Text]]>
when I want to get only 'Text'

Is there any way to remove <![CDATA[]]> ???

I tried with:
$text =~ s|\Q<![CDATA[\E.*?\Q]]>\E||sg;
but I don't get any text.

Thank you very much.
 
this should leave you with whatever is within the square braces

Code:
[b]#!/usr/bin/perl[/b]

$_ = '<![CDATA[Text]]>';

s/<!\[CDATA\[([^]+]*)\]\]>/$1/;

print;


Kind Regards
Duncan
 
Which module are you using for the parsing, or have you rolled your own?

f

&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilkes
 
I tried with:
$text =~ s|\Q<![CDATA[\E.*?\Q]]>\E||sg;
but I don't get any text.

thats because you are substituting the entire pattern with nothing. In effect you are deleting it. This might work doing it more your way (\Q...\E):

$text =~ s|\Q<![CDATA[(.*?)]]>\E|$1|g;

but I didn't test it. If not, Duncans way will give you the text you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top