Home › Forums › Back End › Edit XML with PHP › Re: Edit XML with PHP
Perfect. Now here is a quick xml file writer…
$r = $doc->createElement( “pricing” );//creates
for( $i = 0, $c = count($title); $i < $c; $i++ ) {//loops through your vars...
$b = $doc->createElement( “package” );//creates $a1 = $doc->createElement( “title” );//creates
$a1->appendChild($doc->createTextNode( $title[$i] ) );//places $title[$i]’s value into
$b->appendChild( $a1 );//closes
$a2 = $doc->createElement( “price” );
$a2->appendChild($doc->createTextNode( $price[$i] ) );
$b->appendChild( $a2 );
$a3 = $doc->createElement( “description” );
$a3->appendChild($doc->createTextNode( $description[$i] ) );
$b->appendChild( $a3 );
$r->appendChild( $b );//closes }
$doc->save($xmlLoc);//and save.
?>
I actually didn’t test this, because I don’t want to take the time to set everything up but all looks in order. I commented out so you can see what I did, see if you can figure out how things work. Actually simple once you get it. Modify if needed, best of luck.