xml processing cdata

This is a discussion on xml processing cdata within the PHP General forums, part of the PHP Programming Forums category; I have an xml file with a cdata element like the one below. How would I use the php xml ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-09-2008
Chris W
 
Posts: n/a
Default xml processing cdata

I have an xml file with a cdata element like the one below. How would I
use the php xml functions to extract that cdata and save it as a pdf file?

<attach id="2" display-name="207069.pdf" file-name="207069.pdf"
obj-type="1" system="0">
<![CDATA[eJysumVQW1/0NtoWK95CcXe3EFxK8QDBCQ5 ...... ]]>
</attach>



The code I have is this...

$in = fopen("test.xml", 'r');
$XMLStr = '';
while (!feof($in)) {
$LineNumber++;
$XMLStr .= fgets($in);
}
$XML = simplexml_load_string($XMLStr);
foreach($XML->props->attachments->attach as $Attachment){
print_r($Attachment);
}
The output looks like this...

SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2
[display-name] => 207069.pdf
[file-name] => 207069.pdf
[obj-type] => 1
[system] => 0
)

)


--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"

Ham Radio Repeater Database.
http://hrrdb.com

Reply With Quote
  #2 (permalink)  
Old 05-10-2008
Brady Mitchell
 
Posts: n/a
Default Re: [PHP] xml processing cdata

The last comment on http://php.net/manual/en/function.si...oad-string.php
is what you need:

simplexml_load_string($xmlstring, 'SimpleXMLElement', LIBXML_NOCDATA);

Brady


On May 9, 2008, at 1250PM, Chris W wrote:

> I have an xml file with a cdata element like the one below. How
> would I use the php xml functions to extract that cdata and save it
> as a pdf file?
>
> <attach id="2" display-name="207069.pdf" file-name="207069.pdf" obj-
> type="1" system="0">
> <![CDATA[eJysumVQW1/0NtoWK95CcXe3EFxK8QDBCQ5 ...... ]]>
> </attach>
>
>
>
> The code I have is this...
>
> $in = fopen("test.xml", 'r');
> $XMLStr = '';
> while (!feof($in)) {
> $LineNumber++;
> $XMLStr .= fgets($in);
> }
> $XML = simplexml_load_string($XMLStr);
> foreach($XML->props->attachments->attach as $Attachment){
> print_r($Attachment);
> }
> The output looks like this...
>
> SimpleXMLElement Object
> (
> [@attributes] => Array
> (
> [id] => 2
> [display-name] => 207069.pdf
> [file-name] => 207069.pdf
> [obj-type] => 1
> [system] => 0
> )
>
> )
>
>
> --
> Chris W
> KE5GIX
>
> "Protect your digital freedom and privacy, eliminate DRM, learn more
> at http://www.defectivebydesign.org/what_is_drm"
>
> Ham Radio Repeater Database.
> http://hrrdb.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:03 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0