如何从SimpleXml中提取值?

How can I extract the value from this SimpleXml? I keep getting an empty array, and I don't know what I'm doing wrong.

I just want to extract the string "Familial GI Stromal Tumor With Loss of Heterozygosity and Amplification of Mutant KIT.".

object(SimpleXMLElement)#13 (2) {
  ["@attributes"]=>
  array(2) {
    ["Name"]=>
    string(5) "Title"
    ["Type"]=>
    string(6) "String"
  }
  [0]=>
  string(86) "Familial GI Stromal Tumor With Loss of Heterozygosity and Amplification of Mutant KIT."
}

SimpleXMLElement has a __toString() method. For the element you showed in your question, you should be able to just echo the string content.

echo $yourElement;

or if you want it in a variable, you can call __toString() explicitly

$someVar = $yourElement->__toString();

or trigger it by treating the element as a string;

$someVar = "$yourElement";

Just convert it into a string.

var_dump((string) $element);

Anyway, it depends on your xpath.

Thanks for the help, everyone. Turns out I figured it out. I simply had to access it from the array.

 $title = $pub->xpath('Item[@Name="Title"]')[0];