Jump to content

newbie - parsing xml file question


Transporter_ii

Recommended Posts

Ok, saying I'm not much of a programmer is an understatement, but I'm sitting here with a copy Beginning PHP 5 and MySQL 5, and a working script that I have been trying to modify unsuccessfully for a week now.

 

To make it short, the script parses an XML file formatted like this:

<CHOICES>A, B, C, D</CHOICES>

 

And saves the values to an array like this:

 

save value to "questions" array if this is a CHOICES tag

if ($val[tag] == "CHOICES") {

$questions[$questionNo]['choices'] = $val[value];

 

Note: later on in the script, it "explodes" the data:

 

// split choices into "choices" array

$choices = explode(", ", $questions[0]['choices']);

 

 

 

I really want to format the XML like this:

<CHOICE>A</CHOICE><CHOICE>B</CHOICE> etc.

 

or like this:

 

<CHOICEA>A</CHOICEA><CHOICEB>B</CHOICEB> etc.

 

Is there a way to get data into the array the way I want to do it, but have the data in the array work like it did the way the script was originally structured.

 

Every example I see on parsing an XML file with PHP, seems like it assumes only one set of tags in the XML structure for a certain element, but for what I'm wanting to do, this keeps making me do kludgey workarounds.

 

Any help would be greatly appreciated.

 

Transporter_ii

 

 

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.