homepage Welcome to WebmasterWorld Guest from 54.226.43.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
xml parsing
ktsirig




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

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?

 

eelixduppy




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

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

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

coopster




msg:3625947
 6:52 pm on Apr 13, 2008 (gmt 0)

</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/>';
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved