Hi,
I need to transform the following XML feed into an HTML form using php:
(view source to see the XML or it is in the same directory - feed.xml)
at the moment, the script just parses the feed and displays it but I need to somehow get the form elements and options in the XML to appear on the page as an HTML form. Can someone give me a few pointers on how to do that?
many thanks,
lukemack.
current script:
I need to transform the following XML feed into an HTML form using php:
(view source to see the XML or it is in the same directory - feed.xml)
at the moment, the script just parses the feed and displays it but I need to somehow get the form elements and options in the XML to appear on the page as an HTML form. Can someone give me a few pointers on how to do that?
many thanks,
lukemack.
current script:
PHP:
<?php
/*
Script to test parsing an xml document
*/
//declare some variables for storing the data from each element
$xmlSource="feed.xml";// the xml file we want to parse
// function: startElement
// Deals with the starting element
function startElement( $parser, $tagName, $attrs ) {
echo "<" . strtolower( $tagName ) .">";
}
// function: endElement
// Deals with the ending element
function endElement( $parser, $tagName ) {
echo "</" . strtolower( $tagName ) ."><br>";
}
// function: charElement
// Deals with the text in between tags
function charElement( $parser, $text ) {
echo "$text";
}
// Create an xml parser
$xmlParser = xml_parser_create();
// Set up element handler
xml_set_element_handler( $xmlParser, "startElement", "endElement" );
// Set up character handler
xml_set_character_data_handler( $xmlParser, "charElement" );
// Open connection to RSS XML file for parsing.
$fp = fopen($xmlSource, "r" )
or die( "Cannot read RSS data file." );
// Parse XML data from RSS file.
while( $data = fread( $fp, 4096 ) ) {
xml_parse( $xmlParser, $data, feof( $fp ) );
}
// Close file open handler
fclose( $fp );
// Free xml parser from memory
xml_parser_free( $xmlParser );
?>