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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Nagle

    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.


  • Bruno Desthuilliers

    #2
    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

    Comment

    • Louis M

      #3
      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.

      Comment

      • Tim Tyler

        #4
        Re: Using PHP to generate HTML from the contents of an XML file?

        Louis M <louis@b-it.delete.com.a u> 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.

        Comment

        • Tim Tyler

          #5
          Re: Using PHP to generate HTML from the contents of an XML file?

          Paul Nagle <paulnagle@ocea nfree.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":



          See also:


          --
          __________
          |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.

          Comment

          • Bruno Desthuilliers

            #6
            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


            Comment

            Working...