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</filena me>
<proName>Trake jeep8</proName>
<upLine>PRODUCT #123543</upLine>
<downLine>AGE 5 yrs, up</downLine>
<textFileToload>Trake jeep8.txt</textFileToload>
<flvFileToload>auto.flv</f lvFileTolo ad>
<bigPic>j0331791.jpg</bigP ic>
</image>
</simpleviewerGallery>
The following code always replace the first element and not the one i need!
How should i fix it?
Thanks
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</filena
<proName>Trake jeep8</proName>
<upLine>PRODUCT #123543</upLine>
<downLine>AGE 5 yrs, up</downLine>
<textFileToload>Trake jeep8.txt</textFileToload>
<flvFileToload>auto.flv</f
<bigPic>j0331791.jpg</bigP
</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;
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks anyway