66 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
SteveSolanki says

Hi

Try this out
<?php
$dom = new DOMDocument ( '1.0', 'UTF-8' );
$dom->load('items.xml');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$itemstag = $dom->getElementsByTagName ( 'item' )->item ( 0 );
//new item
$newitem = $dom->createElement ( "item" );
//type
$type = $dom->createAttribute ( 'type' );
$newitem->appendChild ( $type );
$type->appendChild ( $dom->createTextNode ("image" ) );
//src
$src = $dom->createAttribute ( 'src' );
$newitem->appendChild ( $src );
$src->appendChild ( $dom->createTextNode ("5.jpg" ) );
//fade
$fade = $dom->createAttribute ( 'fade' );
$newitem->appendChild ( $fade );
$fade->appendChild ( $dom->createTextNode ("1" ) );
//delay
$delay = $dom->createAttribute ( 'delay' );
$newitem->appendChild ( $delay );
$delay->appendChild ( $dom->createTextNode ("12" ) );
//append new item
$itemstag->parentNode->appendChild ( $newitem );
//save xml
$dom->save("items.xml");
?>
Hope it helps Thanks
66 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
SteveSolanki says

And Here is a version which inserts at random position

<?php
$dom = new DOMDocument ( '1.0', 'UTF-8' );
$dom->load('items.xml');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$total=$dom->getElementsByTagName ( 'item' )->length;
//random
$rand=rand(0,$total-1);
// insert position
$itemstag = $dom->getElementsByTagName ( 'item' )->item ( $rand );
//new item
$newitem = $dom->createElement ( "item" );
//type
$type = $dom->createAttribute ( 'type' );
$newitem->appendChild ( $type );
$type->appendChild ( $dom->createTextNode ("image" ) );
//src
$src = $dom->createAttribute ( 'src' );
$newitem->appendChild ( $src );
$src->appendChild ( $dom->createTextNode ("5.jpg" ) );
//fade
$fade = $dom->createAttribute ( 'fade' );
$newitem->appendChild ( $fade );
$fade->appendChild ( $dom->createTextNode ("1" ) );
//delay
$delay = $dom->createAttribute ( 'delay' );
$newitem->appendChild ( $delay );
$delay->appendChild ( $dom->createTextNode ("12" ) );
//append new item
$itemstag->parentNode->insertBefore ( $newitem,$itemstag );
//save xml
$dom->save("items.xml");
?>

Let me know how it goes

Thanks

315 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

Steve worked great!!!! Thanks everyone who helped!

315 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

One last thing Steve, haha If I added comments in the .xml file like this:

<!-- YOUTUBE -->

<!-- YOUTUBE -->

Do you think that when the add.php script hits it could find one of those comments that are already in the xml and place it there?

If I can get that WOW that would be awesome!

Tim

315 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

One per comment. So if I had 3 comments lines like this :)

<items>

<item type="image" src="1.jpg" fade="1" delay="12"/>
<item type="image" src="2.jpg" fade="1" delay="12"/>
<item type="image" src="3.jpg" fade="1" delay="12"/>
<!-- YOUTUBE -->
<item type="image" src="4.jpg" fade="1" delay="12"/>
<item type="image" src="5.jpg" fade="1" delay="12"/>
<item type="image" src="6.jpg" fade="1" delay="12"/>
<item type="image" src="7.jpg" fade="1" delay="12"/>
<item type="image" src="8.jpg" fade="1" delay="12"/>
<item type="image" src="9.jpg" fade="1" delay="12"/>
<item type="image" src="10.jpg" fade="1" delay="12"/>
<item type="image" src="11.jpg" fade="1" delay="12"/>
<item type="image" src="12.jpg" fade="1" delay="12"/>
<!-- YOUTUBE -->
<item type="image" src="13.jpg" fade="1" delay="12"/>
<item type="image" src="14.jpg" fade="1" delay="12"/>
<item type="image" src="15.jpg" fade="1" delay="12"/>
<item type="image" src="16.jpg" fade="1" delay="12"/>
<item type="image" src="17.jpg" fade="1" delay="12"/>
<!-- YOUTUBE -->
<item type="image" src="18.jpg" fade="1" delay="12"/>
<item type="image" src="19.jpg" fade="1" delay="12"/>
<item type="image" src="20.jpg" fade="1" delay="12"/>

</items>

You guys rock! Thanks so much for everything

66 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
SteveSolanki says

Hi

Try this out.It replaces the comment node with new item

<?php
$dom = new DOMDocument ( '1.0', 'UTF-8' );
$dom->load('items.xml');
//get childnodes
$items=$dom->getElementsByTagName( 'items' )->item(0)->childNodes;
//get count of childnodes
$totalNodes=$dom->getElementsByTagName ( 'items' )->item(0)->childNodes->length;
for($i=0;$i<$totalNodes;$i++){
    //check if comment node
    if ($items->item($i)->nodeType==8)  {    
      //new item
      $newitem = $dom->createElement ( "item" );
      //type
      $type = $dom->createAttribute ( 'type' );
      $newitem->appendChild ( $type );
      $type->appendChild ( $dom->createTextNode ("image" ) );
      //src
      $src = $dom->createAttribute ( 'src' );
      $newitem->appendChild ( $src );
      $src->appendChild ( $dom->createTextNode ("ABHI" ) );
      //fade
      $fade = $dom->createAttribute ( 'fade' );
      $newitem->appendChild ( $fade );
      $fade->appendChild ( $dom->createTextNode ("1" ) );
      //delay
      $delay = $dom->createAttribute ( 'delay' );
      $newitem->appendChild ( $delay );
      $delay->appendChild ( $dom->createTextNode ("12" ) );
      //replace with new item
      $items->item($i)->parentNode->replaceChild($newitem, $items->item($i));
  } 
}
//save xml
$dom->save("items.xml");
?>
315 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

Hey! Thanks!

I didn’t see you answered me till like an hour ago. Sorry!

By the way you rock! Hands down.

Worked great… I’m just trying to figure out now how to make “nodeType==8” just find a certain comment. Its replacing all my comments. I just want to replace a certain one :)

Thanks so much! Really really appreciate it. I’ll have to look at your profile and check some of your files out ;)

Thanks Tim

by
by
by
by
by
by