tags:

views:

29

answers:

1

Hello,

I have a xml file which has an entry

<content type="html"></content>

Can I access it as echo $result->content;

If not let me know , coz the above does not seem to be working, there are pics, which I want to display.

Thanks Jean

+2  A: 
$result = simplexml_load_file("/path/to/file.xml");

should do what you want.

EDIT: You've said that you have the content as HTML. If it's stored as HTML when it's passed to echo it's displayed as HTML content.

However, to get HTML into the XML document in the first place, it needs to be stored either as character entities or as a CDATA section.

If it's character entities, then all you need to do is call:

$result->content = html_entities_decode($result->content);

If you've stored it as CDATA, then you need to change the call to simplexml_load_file to the following:

$result = simplexml_load_file("/path/to/file.xml", "SimpleXMLElement", LIBXML_NO_CDATA);
Macha
You would have noticed the echo, what I need it is to display it as an html content
Jean
@Jean: But you already have this code: `echo $result->content`. Macha only told what `$result` should be. Or don't I get your point?
Felix Kling
I can very well parse the xml file, my issue is I want it as html--<content type="html"></content>
Jean
If it's HTML going in, it's HTML going out... _but_, to store HTML in an XML file, you need to put the HTML as a CDATA section, or replace the angle brackets with character entities.
Macha