This is how I would probably do this, using AS3's E4X capabilities.
private function copyMyProductXMLNodes():void
{
var xmlObj:XML = <productList><product name="notMyProduct">product 1</product><product name="myProduct">product 2</product><product name="notMyProduct">product 3</product><product name="myProduct">product 4</product></productList>;
var myXML:XML = <myProductList></myProductList>;
for each(var productItem:XML in xmlObj.product)
{
if(productItem.@name == 'myProduct')
{
myXML.appendChild(productItem.copy());
}
}
trace(myXML.toXMLString())
}
I instantiated the myXML var with an XML literal, rather than leaving it as new XML() because the appendChild method can't append anything to an XML object until it has a top-level node.
I'd be glad to add a little more commentary on this code, if that would be helpful. Just let me know.