Parsing XML with PHP..need some advice!

Associate
Joined
30 Dec 2005
Posts
415
Ok i've never done this before, but i've suddenly realised its the only solution.

I've got an xml file, which defines form field names, types, descriptions and sizes, as well as to what category they belong to and a few other parameters.
What I want to do is have PHP parse this xml file, and create the form fields accordingly on the page..

So say you have this:

<category="design">
<item="colours" />
<format="dropdown" />
<maxpoints="3" />
<text="Colours of the page" />
</item>
</category>

And the PHP would generate:
Code:
<p>Colours of the page: <select name="design_colours"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option> points. Comments: <input type="text" name="comments_design_colours" />

There would be multiple items within each category, and several categories.
Could anyone give me some help on generating this PHP from the XML file?
 
Augmented said:
Which version of PHP are you on, 4 or 5? This is relatively simple on PHP5, as you can use SimpleXML. It's more tricky in PHP4 as you either need to compile in specific extensions, use 3rd-party packages or write the parser yourself.

Ah damn.

My home server is running PHP 5, but the one its going to be on is PHP 4.
 
Back
Top Bottom