i have an xml structure:

   <B ID="444">
            <child1 /*expected outcome came in here*/> /*sometimes here*/ </child1>
            <child2>data2 <!-instead of here-></child2>
            <child4>data4 /* and also here instead*/</child4>

i made an xpath query to fetch //*B, where child2==data2 and child4==data4 like this:

$query = "//*[@ID=444]//*['data2' and 'data4']";
$result = $xml->xpath($query);

it worked fine. but now, i wanna update data1 and data3; after finding a match, using only simplexml API.

here's what i did, but not working rightly:

    $result[0]['data2'] = "Blabla";
    $result[0]['data4'] = "Blaaaaaaaa";
    return $xml->saveXML($File;

what am i doing wrong ? or how is it better done with simplexml ? any idea will be apprciated.

I think it should be something like this:

$query = "//*[@ID=444]//*[text() = 'data2']";

since you want to find the text value of a node. Am a bit rusty in xpath, so you'll have to try.

Have a look at this tool