473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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.
Jul 17 '05 #1
5 1947
Paul Nagle wrote:
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.


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

Jul 17 '05 #2
Paul Nagle wrote:
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.

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.
Jul 17 '05 #3
Louis M <lo***@b-it.delete.com.au> wrote or quoted:
Paul Nagle wrote:
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? [...]

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.


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/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #4
Paul Nagle <pa*******@oceanfree.net> wrote or quoted:
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?


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/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #5
Louis M wrote:
Paul Nagle wrote:
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.

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.


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
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike | last post by:
I am just wondering if it is possible to save a HTML string from PHPs? Let me elaborate more on what I mean. If you do <?php include 'abc.php' ?> //abc.php <html>
0
by: Nik Coughin | last post by:
Hi, I have an HTML help system that I am generating using the PHP CLI. Essentially it is a single PHP file that has a few arrays at the top of the file, before it starts spitting out HTML, like...
2
by: Waqas Ashraf | last post by:
hi, I am a newbie at xml/xsl. I m trying to generate a book of papers marked up in xml. I have a simple xml file which includes the papers, and i have xsl stylesheet document which generates the...
2
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Asha | last post by:
greetings, i need to upload an .xls file using a secure connection. so i though of using https... can i know how this can be done?
25
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
5
by: grasshopper2 | last post by:
I am looking to build a regular expression that will match pTOC(somenumber) where the number varies between 1& ten, this is to generate a table of contents file that I desperately need to display...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.