Simplify an XMLObject limited to XMLElements with a specific tag

Hello,

I would like to simplify an XMLObject by only retrieving the XMLElements with a specific tag.

I would like a code based with the use of XMLElements as function.

I try this code :

XMLtest3 =  Cases[XMLtest, _XMLElement, Infinity] //. XMLElement[tag : "YO", attributes_, data_] :>  XMLElement[tag , attributes, data]

Definition of the XMLObject:

XMLtest = 
  XMLObject[
    XMLElement["YO", {}, 
      {XMLElement["YO", {}, 2], 
         XMLElement["BA", {}, 
           {XMLElement["YO", {}, 
             {XMLElement["BA", {}, 2]}], XMLElement["BA", {}, 2]}]}]]

I would like to keep only the XMLElements with the tag “YO” and to preserve a tree structure for the XMLObject.

May you help me to correct the code given?

Thank you for your help

Since you want to preserve the tree structure, does this suit your needs?

Cases[XMLtest, XMLElement["YO", {}, _], Infinity]

Thank you for your answer.
But, the Cases function permit to select all the XMLElements with the desired tag but the hierarchical structure (or tree) of the XMLElements is lost.

How about:

DeleteCases[XMLtest, XMLElement[tag_, attributes_, data_] /; tag != "YO", Infinity]