使用PHP搜索XML

trying to add a Ajax search function to a xml file, and found this exemple :

    <?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("my_xml_file.xml");

$x=$xmlDoc->getElementsByTagName('links');

//get the q parameter from URL
$q=$_GET["q"];

//lookup all links from the xml file if length of q>0
if (strlen($q)>0) {
  $hint="";
  for($i=0; $i<($x->length); $i++) {
    $y=$x->item($i)->getElementsByTagName('title');
    $z=$x->item($i)->getElementsByTagName('url');
    if ($y->item(0)->nodeType==1) {
      //find a link matching the search text
      if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) {
        if ($hint=="") {
          $hint="<a href='" . 
          $z->item(0)->childNodes->item(0)->nodeValue . 
          "' target='_blank'>" . 
          $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
        } else {
          $hint=$hint . "<br /><a href='" . 
          $z->item(0)->childNodes->item(0)->nodeValue . 
          "' target='_blank'>" . 
          $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
        }
      }
    }
  }
}

// Set output to "no suggestion" if no hint was found
// or to the correct values
if ($hint=="") {
  $response="no suggestion";
} else {
  $response=$hint;
}

//output the response
echo $response;
?>

This works perfect but the xml I have to search is a bit different and I don't know how to setup the function according to my needs. This is how is formatted my xml :

<data name="my_name"><![CDATA[Data content]]></data>

I changed

`$x=$xmlDoc->getElementsByTagName('links'); to $x=$xmlDoc->getElementsByTagName('data');`

But how to change

 $y=$x->item($i)->getElementsByTagName('title');

to have $y=$x->item($i)-> name; and $z=$x->item($i)->Data content without CDATA ?;

Thanx a lot for your help !!!

add this in your loop:

 $attr = $a->item($i)->getAttribute('name');
if($attr==""){
continue;
}
//take care of the $attr

echo $attr;