Php edit xml

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
freshfitz
Forum Newbie
Posts: 1
Joined: Sun Dec 27, 2009 12:09 am

Php edit xml

Post 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")
  ?>
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Php edit xml

Post 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?
Post Reply