homepage Welcome to WebmasterWorld Guest from 54.167.185.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Decode <![CDATA[ tag in .xml
IngoZ




msg:4366844
 1:08 am on Sep 25, 2011 (gmt 0)

Hi everyone, I have a question: how to extract/decode the data from a CData tag?

I saw this thread [webmasterworld.com...] saw a code:

$TheData = preg_match_all("/<!\[CDATA\[(.*?)\]\]>/s", $data, $string);
$testing = $string[1][0];
$testing = str_replace(array("\r", "\n", "\t", " "), "", $testing);
echo $testing;

$filename = "test.pdf";
/* encode & write data (binary) */
$ifp = fopen($filename, "wb" );
fwrite( $ifp, base64_decode( $testing ) );
fclose( $ifp );


, a solution but I'm a newbie, I don't know how to use it, to implement it, where and how to write the data I want to decode, all I want is to display the decoded data from the CData tag.

Example of code I want to decode:

<![CDATA[
Q1dTCvcFAAB4nKWUT2jTUBzHXzo3mTLd3I7The6iQvpekm5tQlcsDcWpZWNrcR4UsuR1C7Z9IUnXDsT1
JHMHEaaHzcNgggdBRdjJk3jwIGMyPMyD3vQiDHcQFC/1pX+27o9jzkAS3sv3+/n98n2PNwKSgEkAcIYB
SlsrAGCq/UgjACFLT8lDSowtZNJZW6ajPu+445gyhPl83pcXfcQag7wkSRAJUBA4quDsyayjFris3e0N
s2WCgm3NMkzHIFnWHaujJOf0eb1VbCFjbmKztk/VySj2aSQDC6oJeR+CLoeK5KiFVYdYCULS4YirYmNp
1R5no8N+dtAiKWzbtISaDsGd6jo/VugdFhCSOB5xgpDgBZlHMuI55JcRqvNWlBVrHDuqrjpqnZkapAQf
kHlRRiKHejbN27RVO9GN1OSBzFtKNgR3pHewPHVtM04zZ6XLa6RrEKdxBmcdm0bKlyPVNTlFrIzqhFXT
TBua6gJhgbPHiXYzr05gLuXGG4JbwsO2RP8sHt9/kTMZWFPbzhBO7a+2E5MmhkPYJjlLw1TeXd0k8Tjt
xTImsB6zSKbci6laNnb1fd6awRWXq8hG1nbUrIb7lTB1+wxDl2OBQIznA34UEFBvkOelQKQnJgV6FCnA
K6KohOAua42mEy3nhlyl6f9Aq7PWaMQyxgy6n5XDU/dAsOWNtj2nrex2l0JiENWXCsZ6hQjvj/hFRfJH
g5FNXH2JylT/7nAPSuuvD7cyNfA/cfwVseeWhtWDL8yCqIceh6WOefpkQNJavHrpbPLWwto3wDCgRC/Q
2nKOlO4xTzaedQ62cBtFBszNzT1njlGDKIrzbZzodPWuBBuXXrdPrw13f3pZXH4ArIG3S8NHL8+EVq77
iq2zxcFX3h+/hfUvDX0/S49X3y+uTr2YLX7Hnzu/rp86WZI7PDfgifsNb+Y/NnSNzTy6tnzFAQ/R8dPv
QmsXPxRpf83uoe2hHd5panJf4AIdT7d7QPL2wkjzr7tNTQz93PH0fNH98AfcvupI
]]>


Thanks

 

httpwebwitch




msg:4368100
 5:20 am on Sep 28, 2011 (gmt 0)

use PHP's SimpleXML class. But to parse CDATA properly you need to use it in a special way:

$xml = simplexml_load_file($this->filename, 'SimpleXMLElement', LIBXML_NOCDATA);


The key is the LIBXML_NOCDATA option as the third parameter. This returns the XML object with all the CDATA data converted into strings.

read about...

simplexml_load_file:
[us3.php.net...]

simplexml_load_string:
[us3.php.net...]

and the constants you can provide that change how they parse:
[us3.php.net...]

Welcome to WebmasterWorld!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved