How do I parse this XML File - PHP?

  • Thread starter Thread starter savj14
  • Start date Start date
S

savj14

Guest
I assume using SimpleXML would be easiest? I tried a few things but without success.

What I am trying to parse out is Info,Info2,and Gamertag for each XboxInfo.

<ArrayOfXboxInfo>
<XboxInfo>
<PresenceInfo>
<Info>Last seen 1 minute ago</Info>
<Info2/>
<LastSeen>2009-01-06T09:19:42-06:00</LastSeen>
<Online>false</Online>
</PresenceInfo>
<Gamertag>Name</Gamertag>
</XboxInfo>

<XboxInfo>
<PresenceInfo>
<Info>Last seen 10 minutes ago</Info>
<Info2/>
<LastSeen>2009-01-06T09:19:42-06:00</LastSeen>
<Online>false</Online>
</PresenceInfo>
<Gamertag>Name2</Gamertag>
</XboxInfo>
</ArrayOfXboxInfo>
 
You can either use a SAX type parser where you throw the entire xml into the xml_parse function and it calls back as new things are found or you can convert the XML string to a XML Document using something like simplexml_load_string and then traverse the document tree looking for the items you care about
 
Back
Top