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

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.