Click to See Complete Forum and Search --> : Need advice coding: reading in XML and displaying contents in HTML.


OM2
07-19-2007, 06:43 PM
I want to read in an XML file that has HTML code inside, like:

<text1>
<div>
// HTML code
<\div>
</text1>
<text2>
<div>
// HTML code
<\div>
</text2>

etc.

I want to display the HTML in a PHP file, so I will have something like:

<div id=text2>
<?PHP display XML field ?>
</div>

In total, I want something like:

<html>
<head>

<?php
read in XML file
store somewhere, like in an array
?>

</head>

<body>

<div id=text1>
<?PHP Display XML field?>
</div>

<div id=text2>
<?PHP Display XML field?>
</div>

</body>
</html>

Is there anything wrong with the above??
As far as I'm concerned... the above should be very straight forward and simple to do.
Or a I missing something?
I'm not the experienced in PHP... still learning.

Any help would be appreciated.

Thanks.


OM

NogDog
07-19-2007, 07:47 PM
First off, your XML file will need to use the CDATA tag to differentiate the HTML content from XML tags:

<?xml version="1.0"?>
<content>
<text><![CDATA[<div>
<p>HTML content</p>
</div>
]]></text>
<text><![CDATA[<div>
<p>More HTML content</p>
</div>
]]></text>
</content>

If running PHP5, you can use the SimpleXML functions (http://www.php.net/simplexml) to parse the XML file.

OM2
07-20-2007, 04:20 AM
thanks for the reply.
that really helps.

ok... i'll do research on reading in the xml.

but... how about displaying the xml after having read it in?
i'm a little eonfused about this.
(mainly because i'm a newbie!)

i want to have something like:
<div id=text2>
<?PHP display XML field ?>
</div>
let's assume i have read into an array... so i would have something like:<div id=text2>
<?PHP echo myArray[text2] ?>
</div>let me know what you think.

thanks.