Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: "CDATA Parsing and XML"

by fokat (Deacon)
on Mar 31, 2003 at 02:06 UTC ( [id://246834]=note: print w/replies, xml ) Need Help??


in reply to Re: "CDATA Parsing and XML"
in thread "CDATA Parsing and XML"

First of all, a ++ is in order because you shown another approach to the problem.

I guess your example might not work as expected, because the regexp is greedy, so if the XML contains more than one CDATA sections, only the first will be seen. I made slight adjustments as shown below...

#!/usr/bin/perl use strict; use warnings; my $cdata = join('', <DATA>); while ($cdata =~ s/<!\[CDATA\[(.*?)\]\]>/$1/ms) { print "cdata = $1\n"; } __DATA__ <?xml version="1.0" encoding="UTF-8" ?> <![CDATA[This is the first cdata]]> <![CDATA[This is the second cdata]]> <some/>

So that it outputs...

cdata = This is the first cdata cdata = This is the second cdata

Also, probably hating dot star is in order, but I can't think about a better regexp right now :) .

Best regards

-lem, but some call me fokat

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246834]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found