Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML and PHP

Status
Not open for further replies.

rjonesX

Technical User
Joined
Jun 18, 2001
Messages
56
Location
US
So here is what I am working with, if anyone can provide any assistance I would be hugely appreciative.

First the basic xml...
<story>
<title>russ</title>
<para1>hereispara1</para1>
</story>

Now, I use this same xml structure for several things, news stories, calendar dates, etc. So I want to create a single php file that picks up variables from a form and replaces those in the existing PHP.

For example... if I had a form like <input type=text name=Title><input type=text name=para01>, i would like whatever came from this first variable that was submitted to the form (in this case &quot;title&quot;) to replace whatever is in the first node of the xml file... I dont want to match names of nodes though, I would highly prefer using something of an array,

maybe like $_POST[0] would somehow get into $storynode[0] which would mean that the new title would get inserted in the old title. This is how I have tried it so far, but when it gets to the dump_mem(); nothing has changed in the xml file, as if the set_content(); didnt work at all. Any ideas?

<?
$xmlDoc = domxml_open_file('whatever.xml');
$root = $xmlDoc->document_element();
$tobeupdated = $root->children();

for($a=0; $a<sizeof($tobeupdated); $a++)
{
$textnode = $tobeupdated[$a]->first_child();
$textnode->set_content($_POST[$a]);
}

echo $xmlDoc->dump_mem();

$xmlDoc->dump_file('whatever.xml', false, false);

?>
 
 0
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top