Jump to content
#StayAtHome ×
Sign in to follow this  
branmh

XML and issues with CDATA

Recommended Posts

Having an issue within the <description> node, it contains a header line and then followed by <![CDATA[ story paragraph [/size]]]>. 

How to create another variable for everything inside the CDATA? and/or how to remove that entirely? Thanks in advance.  

//this remove all a href from rawdata
$rawdata = preg_replace('@<a href=[^>]+>(.*)</a>@', '', $rawdata);
$rawdata = preg_replace('/<pre>/', '', $rawdata);
$rawdata = preg_replace('/<\/pre>/', '', $rawdata);
$rss_update = preg_match_all("/<pubDate>(.*)<\/pubDate>/", $rawdata, $rss_update);
 
$types = array(
'link',
'description',
'title',
'pubDate',
'author');
 
 
$valid = array();
$link = $description = $title = $pubDate = $author = array();
 
$rawdata = preg_replace('/<item>/', "<item>\s", $rawdata);
if (preg_match_all('/<item>(.+?)<\/item>/s', $rawdata, $r))
{
$rr = count($r[0]);
for ($i = 0; $i < $rr; $i++)
{
if (preg_match_all('/<(.+?)>(.+?)<\//s', $r[1][$i], $y))
{
$yy = count($y[0]);
for ($x = 0; $x < $yy; $x++)
{
if (in_array($y[1][$x], $types))
{
array_push(${$y[1][$x]}, $y[2][$x]);
 
} 
}
}   
}
 
}
if ($this->debug)
echo "rss total  $i\n";
$this->smarty->assign('rss_update', $rss_update);
$this->smarty->assign('rss_link', $link);
$this->smarty->assign('rss_description', $description);
$this->smarty->assign('rss_title', $title);
$this->smarty->assign('rss_pubdate', $pubDate);
$this->smarty->assign('rss_author', $author);
$this->smarty->assign('rss_story', $story);
$this->smarty->assign('rss_total', $i);
Edited by requinix

Share this post


Link to post
Share on other sites

Step 1: stop using regular expressions to parse XML. There are better alternatives.

 

There is no step 2. The CDATA stuff won't be a problem because libraries that can parse XML know how to handle it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.