Connecting Tech Pros Worldwide Forums | Help | Site Map

Using PHP to generate HTML from the contents of an XML file?

Paul Nagle
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,
Can anyone direct me to an example of where PHP is used to parse a basic
XML file, and use the contents of this file to generate a HTML page? I am
trying to implement a troubleshooting app, where the different paths or
scenarios through the troubleshooter are stored in an XML file, and
presented to the user through a series of radio buttons.
I need to implement this using PHP and have very little experience. Any help
would be greatly appreciated.

Thanks,
Paul.



Bruno Desthuilliers
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Using PHP to generate HTML from the contents of an XML file?


Paul Nagle wrote:[color=blue]
> Hi,
> Can anyone direct me to an example of where PHP is used to parse a basic
> XML file, and use the contents of this file to generate a HTML page? I am
> trying to implement a troubleshooting app, where the different paths or
> scenarios through the troubleshooter are stored in an XML file, and
> presented to the user through a series of radio buttons.
> I need to implement this using PHP and have very little experience. Any help
> would be greatly appreciated.[/color]

The options are :
- parsing the XML file with a SAX parser. It's the simplest parser, but
maintains no state so you have to do it by yourself.
- parsing the XML file with a DOM parser. It builds an in-memory
representation of the XML data as a tree of objects. Probably not the
simplest choice here
- transforming the XML to HTML with XSLT. You have to learn XSLT and
write the approriate XSL stylesheets, but that's not that complex, and
once done the PHP code by itself is quite simple.

You may want to try XSLT ?-)

My 2 cents,
Bruno

Louis M
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Using PHP to generate HTML from the contents of an XML file?


Paul Nagle wrote:
[color=blue]
> Hi,
> Can anyone direct me to an example of where PHP is used to parse a basic
> XML file, and use the contents of this file to generate a HTML page? I am
> trying to implement a troubleshooting app, where the different paths or
> scenarios through the troubleshooter are stored in an XML file, and
> presented to the user through a series of radio buttons.
> I need to implement this using PHP and have very little experience. Any help
> would be greatly appreciated.
>
> Thanks,
> Paul.
>
>[/color]
XSLT adds another layer of complexity which may be overkill unless you
adopt it across your presentation logic. Parsing with SAX parser is
probably the most straight forward, so long as you dont need to refer to
the XML document more than once during the process.

Use the Expat XML library from www.jclark.com/xml.
Tim Tyler
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Using PHP to generate HTML from the contents of an XML file?


Louis M <louis@b-it.delete.com.au> wrote or quoted:[color=blue]
> Paul Nagle wrote:[/color]
[color=blue][color=green]
> > Can anyone direct me to an example of where PHP is used to parse a basic
> > XML file, and use the contents of this file to generate a HTML page? [...][/color][/color]
[color=blue]
> XSLT adds another layer of complexity which may be overkill unless you
> adopt it across your presentation logic. Parsing with SAX parser is
> probably the most straight forward, so long as you dont need to refer to
> the XML document more than once during the process.
>
> Use the Expat XML library from www.jclark.com/xml.[/color]

As described on http://uk.php.net/xml

It seems like agony to have to use a C library to parse XML :-|
--
__________
|im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
Tim Tyler
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Using PHP to generate HTML from the contents of an XML file?


Paul Nagle <paulnagle@oceanfree.net> wrote or quoted:
[color=blue]
> Can anyone direct me to an example of where PHP is used to parse a basic
> XML file, and use the contents of this file to generate a HTML page?[/color]

Maybe look at "SAXY":

http://www.engageinteractive.com/flashSite/saxy.html

See also:

http://pear.php.net/package/XML_HTMLSax
--
__________
|im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
Bruno Desthuilliers
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Using PHP to generate HTML from the contents of an XML file?


Louis M wrote:[color=blue]
> Paul Nagle wrote:
>[color=green]
>> Hi,
>> Can anyone direct me to an example of where PHP is used to parse a
>> basic
>> XML file, and use the contents of this file to generate a HTML page? I am
>> trying to implement a troubleshooting app, where the different paths or
>> scenarios through the troubleshooter are stored in an XML file, and
>> presented to the user through a series of radio buttons.
>> I need to implement this using PHP and have very little experience.
>>
>>[/color]
> XSLT adds another layer of complexity which may be overkill unless you
> adopt it across your presentation logic. Parsing with SAX parser is
> probably the most straight forward, so long as you dont need to refer to
> the XML document more than once during the process.[/color]

My experience is that XSLT is the most straightforward way to produce
HTML from XML, and is far more simple (and more flexible) than manually
writing code to maintain current state etc, which you have to do with a
SAX parser - at least as soon as the transformation is just a bit more
than a 'tag-to-tag' translation.

But then, experience and opinion may differ !-)

<OP>
I think you'll have to try both ways and decide by yourself...
</OP>

Bruno


Closed Thread