71 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+1 more
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
71 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+1 more
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

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

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

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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

71 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+1 more
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");
?>
320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by