ktsirig Posted April 12, 2008 Share Posted April 12, 2008 Hello all, I need to parse some xml documents. I use Simple:XML and it works ok up to the point of matching elements that occur just once in my documents. How can I process something like: <PubmedArticle> <AuthorList CompleteYN="Y"> <Author ValidYN="Y"> <LastName>Wilde</LastName> <ForeName>A</ForeName> <Initials>A</Initials> </Author> <Author ValidYN="Y"> <LastName>Reaves</LastName> <ForeName>B</ForeName> <Initials>B</Initials> </Author> <Author ValidYN="Y"> <LastName>Banting</LastName> <ForeName>G</ForeName> <Initials>G</Initials> </Author> </AuthorList> </Article> </PubmedArticle> and print all Authors' names? Quote Link to comment https://forums.phpfreaks.com/topic/100793-xml-parse/ Share on other sites More sharing options...
Daniel0 Posted April 12, 2008 Share Posted April 12, 2008 Try this: <?php $xml = SimpleXML($data); $authors = $xml->xpath('AuthorList/Author'); foreach($authors as $author) { echo "{$author->ForeName} {$author->LastName}\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/100793-xml-parse/#findComment-515483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.