Page 1 of 1

Php edit xml

Posted: Sun Dec 27, 2009 12:11 am
by freshfitz
I need a php script that will edit this xml can anyone help me out?

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<item>
   
    <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   <list>
    <title>My daughter photo 1</title> 
    <description>images content demo for dynamic xml with lightbox,using images demo here.</description>
    <link>http://www.flashden.net/user/wangruyi</link>
     <thumb>thumb/2.jpg</thumb>
       <content width="" height="">contentpic/2.jpg</content>
   </list>
   
  
   
   
  
</item>

This code will update the xml but I need an editable form that will execute this code

Code: Select all

<?php
  $item = array();
  $item [] = array(
  'title' => 'My daughter photo 1',
  'description' => 'images content demo for dynamic xml with lightbox,using images demo here.',
  'link' => "",
  'thumb' => "thumb/2.jpg",
  'content' => "contentpic/2a.jpg"
  );
   $item [] = array(
  'title' => 'My daughter photo 2',
  'description' => 'images content demo for dynamic xml with lightbox,using images demo here.',
  'link' => "",
  'thumb' => "thumb/2.jpg",
  'content' => "contentpic/3.jpg"
  );
    $item [] = array(
  'title' => 'My daughter photo 3',
  'description' => 'images content demo for dynamic xml with lightbox,using images demo here.',
  'link' => "",
  'thumb' => "thumb/2.jpg",
  'content' => "contentpic/4.jpg"
  );
  
  $doc = new DOMDocument();
  $doc->formatOutput = true;
  
  $r = $doc->createElement( "item" );
  $doc->appendChild( $r );
  
  foreach( $item as $list )
  {
  $b = $doc->createElement( "list" );
  
  $title = $doc->createElement( "title" );
  $title->appendChild(
  $doc->createTextNode( $list['title'] )
  );
  $b->appendChild( $title );
  
  $description = $doc->createElement( "description" );
  $description->appendChild(
  $doc->createTextNode( $list['description'] )
  );
  $b->appendChild( $description );
  
  $link = $doc->createElement( "link" );
  $link->appendChild(
  $doc->createTextNode( $list['link'] )
  );
  $b->appendChild( $link );
 
  $thumb = $doc->createElement( "thumb" );
  $thumb->appendChild(
  $doc->createTextNode( $list['thumb'] )
  );
  $b->appendChild( $thumb );
    
  $content = $doc->createElement( "content" );
  $content->appendChild(
  $doc->createTextNode( $list['content'] )
  );
  $b->appendChild( $content );
  
  
  $r->appendChild( $b );
  }
  
  echo $doc->saveXML();
  $doc->save("list.xml")
  ?>

Re: Php edit xml

Posted: Sun Dec 27, 2009 1:06 am
by omniuni
Well, let's try to break this down a bit. Rather than having to look through all your code, can you provide a very simple example? When information is entered into the form, where will it go to?