I don't use simple_xml but the approach below, using DOMDocument and DOMXPath should be easy enough to port to simple_xml if desired. Initially I thought you were looking for child nodes of STOK_KODU but the structure of the XML suggests otherwise. The XPath query will find the node with the relevant $product_code from which you can easily find the parent and thus any/all of it's children.
$file='http://xml.aksel.com.tr/Xml.aspx?SK=d021da08&CK=50288';
#$file='c:/temp/Xml.xml'; /* saved locally to test */
$output=array();
$product_code=13775;
$query='//XMLWEBDATA/STOK_KODU[ contains( text(), "'.$product_code.'" ) ]';
$dom=new DOMDocument;
$dom->load( $file );
$xp=new DOMXPath( $dom );
$col=$xp->query( $query );
if( $col && $col->length > 0 ){
foreach( $col as $node ){
/* get the parent */
$parent=$node->parentNode;
$data=array();
for( $i=0; $i < $parent->childNodes->length; $i++ ){
$tag=$parent->childNodes->item( $i )->tagName;
$value=$parent->childNodes->item( $i )->nodeValue;
if( !empty( $tag ) && !empty( $value ) ) $data[ $tag ]=$value;
}
$output[]=$data;
}
/* remove duplicates if there are any */
$output=array_unique( $output );
}
$xp = $dom = null;
/* process the results accordingly */
if( !empty( $output ) ){
foreach( $output as $obj ){
printf('<pre>%s</pre>', urldecode( http_build_query( $obj, null, PHP_EOL ) ) );
}
}
The output of which will be
STOK_KODU=13775
STOK_ADI=CHIP EPSON C3800 Black (S051127)
LISTEFIYAT=2,73
STOKBAKIYE1=16
GRUPKODU=DOLUM ÜRÜNLERİ GRUBU
KOD1=TONER DOLUM ÜRÜNLERİ
KOD2=ÇİPLER
PARABIRIMI=$
KULL5N=9500
RESIMURL=http://xml.aksel.com.tr/Photo.aspx?ID=22705&STOK=13775
To access each field as a variable ( which is what I understand your comment to be )
foreach( $col as $node ){
/* get the parent */
$parent=$node->parentNode;
$data=array();
for( $i=0; $i < $parent->childNodes->length; $i++ ){
try{
/* test node type to avoid errors */
if( $parent->childNodes->item( $i )->nodeType==XML_ELEMENT_NODE ){
$tag=$parent->childNodes->item( $i )->tagName;
$value=$parent->childNodes->item( $i )->nodeValue;
if( !empty( $tag ) && !empty( $value ) ) $data[ $tag ]=$value;
}
}catch( Exception $e ){
echo $e->getMessage();
continue;
}
}
$output[]=$data;
}
and to access as variables, use extract
if( !empty( $output ) ){
foreach( $output as $obj ){
extract( $obj );
printf("<pre>%s\n%s\n%s</pre>", $STOK_KODU, $STOK_ADI, $GRUPKODU );
}
}
$product_codethat gives multiple products in return?