Official Left Turn Solutions Development Blog
Profile Blog Photos Subscribe Syndicate Search Contact Me  
Topics
Code Snippets
Eddy
MySQL
News
PHP
Tutorials
Yahoo APIs
My Photos
Corporate
Members
Sign In

Entries in "Code Snippets"
1
Code Snippets: Perl: Unescape Tags
0 Comments / Subscribe To Comments
Published: Feb.13.2007 @ 11:04 am | Last edited: Feb.13.2007 @ 5:42 pm

One common operation that needs to be performed when pulling xml or html from another source, such as an rss feed or screen scrape, is unescape the tags received from the foreign data source. The following two lines of perl code below illustrates how to pull this off using two simple regular expressions. As always, comments and suggestions are welcome.

$xml =~ s/&lt;/</g;
$xml =~ s/&gt;/>/g;

Code Snippets: Perl: Remove CData Tags from XML
1 Comments / Subscribe To Comments
Published: Feb.13.2007 @ 9:53 am | Last edited: Feb.13.2007 @ 5:40 pm

It is no secret that one of Perls strong points is its robust built in support for regular expressions. If you are not familiar with regular expressions, here is an excellent tutorial site for starters. The following two lines of Perl will remove CData start and end tags from an xml string. As always in Perl there is more than one way to do it, and if any one has a suggestion to improve this code snippet please post a comment or send an email through the contact page.

Assuming you have a scalar named $xml that contains your xml string with CData tags inside:

$xml =~ s/<!\[CDATA\[//g;
$xml =~ s/\]\]>//g;


Current Page 1
1

   
| Report Member | Free Blog BlogText.org