I'm trying to parse some XML data to get the value of a certain attribute - Specifically, I want to find the author. Below is a very cut-down but valid example. The R
node is repeated multiple times.
<GSP VER="3.2">
<RES SN="1" EN="10">
<R N="4" MIME="application/pdf">
<Label>_cse_rvfaxixpaw0</Label>
<PageMap>
<DataObject type="metatags">
<Attribute name="creationdate" value="D:20021024104222Z"/>
<Attribute name="author" value="Diana Van Winkle"/>
</DataObject>
</PageMap>
</R>
</RES>
</GSP>
Currently I do:
$XML = simplexml_load_string($XMLResult);
$XMLResults = $XML->xpath('/GSP/RES/R');
foreach($XMLResults as $Result) {
$Label = $Result->Label;
$Author = ""; // <-- How do I get this?
}
Can someone please explain to me how I can pull out the "author" attribute? The author attribute will be present a maximum of 1 times but may not be present at all (I can handle that myself)