Jump to content


Photo

PHP / XML HELP!


  • Please log in to reply
3 replies to this topic

#1 jvargas

jvargas
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 October 2006 - 06:02 PM

Hello everyone,

First let me thank anyone who replies in advance.

My dilema is as follows:
I have an HTML form that sends information to a php script that writes an XML file for me. This is fine.

The form contains 3 fields: id, path, name.

What I need to do is continue to apend to the XML anytime the form is submited before the ending node.
Here is an example:

XML FILE

<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album id="1" path="carShow" name="some auto show" />

</gallery>

Here is what I need to apend to the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album id="1" path="carShow" name="some auto show" />

<album id="2" path="album" name="another album" />  <--- Information from the HTML form added here before the ending node.

</gallery> <---- Ending node

Is this possible?

Thank you.
Jay


#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 11 October 2006 - 06:16 PM

Try something like this:

$output = "<album";
foreach($_POST as $key => $value)
{
	$output .= " {$key}=\"{$value}\"";
}
$output .= " />";

echo $output;


#3 jvargas

jvargas
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 October 2006 - 06:44 PM

Hi,

Thank you for this. I apologize, but would you please explain the code.

Thank you.

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 11 October 2006 - 06:50 PM

Of course. First line assigns <album to $output.

Then you run through each POST variable and add it to output, then you add the ' />' to close the tag. Finally it is echoed.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users