Hi there,
I am new to parsing XML with PHP and have found a class that has parsed my XML from AFP very nicely into a multidimensional array:
However... I cannot access the values at all..
For example.. I thought I could do this:
but this returns nothing..
How can I iterate through the [newComponent] array to display the headlines and the associated xml file with the content for that headline?
Any pointers greatly appreciated.. I have been banging my head for two days over this now.. :-(
Thanks.
N.
Nematoth
I am new to parsing XML with PHP and have found a class that has parsed my XML from AFP very nicely into a multidimensional array:
Code:
Array
(
[NewsML] => Array
(
[Catalog attr] => Array
(
[Href] => [URL unfurl="true"]http://www.afp.com/dtd/AFPCatalog.xml[/URL]
)
[Catalog] =>
[NewsEnvelope] => Array
(
[DateAndTime] => 20051107T233033Z
)
[NewsItem] => Array
(
[Identification] => Array
(
[NewsIdentifier] => Array
(
[ProviderId] => afp.com
[DateId] => 20051107
[NewsItemId] => mmd--english--webwires--shared--football
[RevisionId attr] => Array
(
[PreviousRevision] => 0
[Update] => N
)
[RevisionId] => 1
[PublicIdentifier] => urn:newsml:afp.com:20051107:mmd--english--webwires--shared--football:1
)
[NameLabel] => Football
)
[NewsManagement] => Array
(
[NewsItemType attr] => Array
(
[FormalName] => News
)
[NewsItemType] =>
[FirstCreated] => 20051107T233033Z
[ThisRevisionCreated] => 20051107T233033Z
[Status attr] => Array
(
[FormalName] => Usable
)
[Status] =>
)
[NewsComponent] => Array
(
[AdministrativeMetadata] => Array
(
[Provider] => Array
(
[Party attr] => Array
(
[FormalName] => AFP
)
[Party] =>
)
)
[DescriptiveMetadata] => Array
(
[Language attr] => Array
(
[FormalName] => en
)
[Language] =>
)
[NewsComponent] => Array
(
[0] => Array
(
[NewsLines] => Array
(
[HeadLine] => Nolan sends Bolton third
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107231401.u0lwsyxa.xml
)
[NewsItemRef] =>
)
[1] => Array
(
[NewsLines] => Array
(
[HeadLine] => Eto'o, Drogba among runners for CAF Player of the Year award
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107153929.xld3y3yl.xml
)
[NewsItemRef] =>
)
[2] => Array
(
[NewsLines] => Array
(
[HeadLine] => Old Firm prepare for cup clash
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107211054.83jkvjaf.xml
)
[NewsItemRef] =>
)
[3] => Array
(
[NewsLines] => Array
(
[HeadLine] => Chelsea won't suffer Gunners' fate, insists Mourinho
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107180334.jakbj0oj.xml
)
[NewsItemRef] =>
)
[4] => Array
(
[NewsLines] => Array
(
[HeadLine] => US book World Cup tune-up friendly with Norway
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107161842.8vvlqprd.xml
)
[NewsItemRef] =>
)
[5] => Array
(
[NewsLines] => Array
(
[HeadLine] => Blues hoping fit crew can steer ship out of trouble
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107124651.2bwqr2j7.xml
)
[NewsItemRef] =>
)
[6] => Array
(
[NewsLines] => Array
(
[HeadLine] => Shearer aims for end-of-the-month comeback after hernia op
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107170901.hd0qouon.xml
)
[NewsItemRef] =>
)
[7] => Array
(
[NewsLines] => Array
(
[HeadLine] => Hearts fans hostile to Rix appointment
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107233029.v2hqnq5i.xml
)
[NewsItemRef] =>
)
[8] => Array
(
[NewsLines] => Array
(
[HeadLine] => Football-hungry Desailly quits Qatar
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107154300.ju7fncg5.xml
)
[NewsItemRef] =>
)
[9] => Array
(
[NewsLines] => Array
(
[HeadLine] => United performance has silence critics: Ferdinand
)
[NewsItemRef attr] => Array
(
[NewsItem] => 051107171104.nwi6annd.xml
)
[NewsItemRef] =>
)
)
)
)
)
)
However... I cannot access the values at all..
For example.. I thought I could do this:
Code:
echo $data["NewsML"]["catalog"]["NewsItem"]["NewsComponent"]["NewsComponent"]["NewsLines"]["HeadLine"];
but this returns nothing..
How can I iterate through the [newComponent] array to display the headlines and the associated xml file with the content for that headline?
Any pointers greatly appreciated.. I have been banging my head for two days over this now.. :-(
Thanks.
N.
Nematoth