Link to home
Start Free TrialLog in
Avatar of tzvio
tzvio

asked on

find xml element by attribute using php

Hi.
I'm trying to read an xml file and replace a specific element data by using attribute id.

that's the xml structure:
<simpleviewerGallery>
<image id="4">
  <filename>ani4.swf</filename>
  <proName>Trake jeep8</proName>
  <upLine>PRODUCT #123543</upLine>
  <downLine>AGE 5 yrs, up</downLine>
  <textFileToload>Trake jeep8.txt</textFileToload>
  <flvFileToload>auto.flv</flvFileToload>
  <bigPic>j0331791.jpg</bigPic>
  </image>
</simpleviewerGallery>

The following code always replace the first element and not the one i need!
How should i fix it?

Thanks



$xml=simplexml_load_file('../pic/'.$galleryName.'/pic.xml');
foreach ($xml->image as $image) {
  if ($xml->image->attributes("id")==$id){
     $xml->image->proName=$proName;
     $xml->image->upLine=$upLine;
     $xml->image->downLine=$downLine;
     if ($video)
        $xml->image->flvFileToload=$video;
     if ($picture)
        $xml->image->bigPic=$picture;
     $xml->image->textFileToload=$proName.".txt";
     break;
  }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tzvio
tzvio

ASKER

i don't need that code anymore
thanks anyway