- Where Developers Learn, Share, & Build Careers
I have an object, which has some XML metadata in the form of a property named Metadata XML. I need to capture values within XML tags and store them in php variables. I have been able to do this on the XML structure:
[MetadataXML] => "& Lt; metadata & gt; title & gt; a title & lt; / titel & gt; & lt; body & gt; some text in body & lt; / body & gt; & lt; / metadata & gt;" with this code:
$ meta = simplexml_load_string ($ item-> metadata xml); $ Heading = (string) $ meta-> Title; $ Body = (string) $ meta- & gt; the body; But now I have an XML structure that looks like this:
& lt; Metadata & gt; & Lt; Two_related_books & gt; & Lt; Book & gt; & Lt; ID & gt; 20 & lt; / Id & gt; & Lt; Title & gt; A title & lt; / Title & gt; & Lt; / Book & gt; & Lt; Book & gt; & Lt; ID & gt; 55 & lt; / Id & gt; & Lt; Title & gt; Other title & lt; / Title & gt; & Lt; / Book & gt; & Lt; / Two_related_books & gt; & Lt; / Metadata & gt; I have tried to loop through book items in many different ways, in any way to get value within the ID and title tags of each book. But some have failed to recover. I have also tried to use XPath.
Does anyone have to do this?
Something like this should work:
$ meta = Simplexml_load_string ($ object-> metadata xml); Forex currency ($ meta-> two_related_books-> book $ book) {echo $ book- & gt; Id; Echo $ book- & gt; Title; }
Comments
Post a Comment