Parsing xml by attributes and nodes


I’d be really grateful if someone could help get me started with parsing xml using simplexml_load_file.

Here’s the xml in extracts:

<?xml version=“1.0” encoding=“UTF-8” ?>

  • <getHistogramsResponse>

  • <aspectHistogramContainer>
    <domainDisplayName>Video Games</domainDisplayName>

  • <aspect name=“Platform”>

  • <valueHistogram valueName=“Sony PlayStation”>

  • <valueHistogram valueName=“PC”>

  • <valueHistogram valueName=“Sony PlayStation 2”>


  • <aspect name=“Genre”>

  • <valueHistogram valueName=“Action, Adventure”>

  • <valueHistogram valueName=“Arcade”>

  • <aspect name=“Rating”>

  • <valueHistogram valueName=“EC - Early Childhood”>

  • <valueHistogram valueName=“E - Everyone”>


  • <conditionHistogramContainer>

  • <conditionHistogram>

  • <conditionHistogram>

  • <condition>


I know I need to drill down through the xml nodes but I am struggling with the correct syntax for filtering using both attributes and elements.

For example, how would I target each of the platform options then move on to each of the condition options.

All advice very much appreciated.


Rather than reinvent the wheel take a look at this thread.

Salathe explains it really well, it helped me a lot.


Thanks Colin,

I suspect I need to slow down a bit to get to grips with this properly. Appreciate the link.