将xml对象的部分保存为对象

I created an xml file that stores some information for me. Now I want to get elements that meet some conditions.

At the moment this looks like this:

Function getElements($xmlObject, $name){

    foreach($xmlObject->feature as $feature){

    if(stristr($feature->path, $name))){    
     array_push($aSubFeatures, $feature);

    }
    }

    return $obj;
}

But I'd prefer getting an object as a return value. I used simpleXML for getting the xml file as an object.

I also tried using DOM (creating new DOMDocument and tried to append the gotten feature element objects) but without reasonable result.

Would deleting all not matching parts of the xml a solution? Did not found a way to delete special elements...

Thanks for your help

For appending an element of a current existing DOMDocument into a new DOMDocument you have to call $newdom->importNode($nodeInOldDOM). You cannot do a regular appendChild of a node from another document.