Welcome to WebmasterWorld Guest from 54.162.141.212

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

xml parsing

     
12:29 pm on Apr 12, 2008 (gmt 0)

5+ Year Member



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?

4:36 am on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



It would be something like this, which you have to include in a loop:

foreach($xml->Author as $author)
echo $author->LastName.'<br/>';
6:52 pm on Apr 13, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



</Article>

What's this? You should be getting an error in your tag mismatches.

After you fix that (remove it) you will have to go another node deeper in your xml object to get the Author information:

foreach($xml->AuthorList->Author as $author) { 
echo $author->LastName.'<br/>';
}
 

Featured Threads

Hot Threads This Week

Hot Threads This Month