I have an object, that has some xml metadata as a property named MetadataXML. I need to grab the values inside the xml tags and store them in php variables. I have succeeded doing it on this xml structure:
[MetadataXML] =>
"<metadata>
<title>A title</titel>
<body>Some text in the body</body>
</metadata>"
with this code :
$meta = simplexml_load_string($object->MetadataXML);
$title = (string)$meta->title;
$body = (string)$meta->body;
But now I have a xml structure that looks like this:
<metadata>
<two_related_books>
<book>
<id>20</id>
<title>A title</title>
</book>
<book>
<id>55</id>
<title>Another title</title>
</book>
</two_related_books>
</metadata>
I have tried to loop through the book items in several different ways, to somehow get the values inside the id and title tags for each book. But have been unsuccessful in retrieving anything. I have also tried using XPath.
Does anyone know how to do it?
Something like this should work: