Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Dynamic XML Conversion Using The SAX Parser And A Stack
Thinking Up Some XML Tags
First you have to identify repeating elements of your web page. This can be menus, headlines, links, shopping cart products and so on. Then look at the parameters you want to assign to your elements. Look at this example XML, and you will get the idea:
file test.pxml:
<doc title="Pizza menu" bgcolor="lightblue">
	<bigheadline>
		Pizza Palace - Our Menu for  <dayofweek />
	</bigheadline>
	<br /><br />
	<b>Buon appetito!!!</b>
	<br /><br />
	
	<nicebox bordercolor="green">
		<product id="0" /><br />
		<product id="1" /><br />
		<product id="2" /><br />
		<product id="3" /><br />
		<product id="4" /><br />
	</nicebox>
</doc>
Dynamically Constructing XML
PHP doesn't care if it is embedded in HTML or XML. So if we use a little trick, we are able to use PHP to construct our XML.
This function creates an output buffer, opens and executes a file using the include-function, and returns the contents of the output buffer.

<?php
function LoadAndExec($filename) {
    
ob_start();
    include(
$filename);
    
$content=ob_get_contents();
    
ob_end_clean();
    return
$content;
}
?>
So now we can create the XML on the fly:
file test.pxml:
<doc title="Pizza menu" bgcolor="lightblue">
	<bigheadline>
		Pizza Palace - Our Menu for  <dayofweek />
	</bigheadline>
	<br /><br />
	<b>Buon appetito!!!</b>
	<br /><br />
	
	<nicebox bordercolor="green">

        <?php for($x=0;$x<5;$x++){ ?>
            <product id="<?php echo $x;?>" /><br />
        <?php } ?>
</nicebox> </doc>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
xml SAXMadhavi08/18/05 03:40
querysantanu Mandal02/11/05 06:55
please help?shimi12/11/04 11:17
existing applicationStephan Schmidt05/01/03 17:11
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.