user2631534
user2631534

Reputation: 477

query XML file and loop through only nodes that have specific element names and attribute values

I have one xml file, which is 16.4MB in size. I need to select and print only the programme nodes that have a channel attribute value of:

BHT 1

here is xml file url: http://epg.com/epg.xml

Upvotes: 0

Views: 241

Answers (1)

Bensonius
Bensonius

Reputation: 1541

Would something like this work?

 $epgdoc = new DOMDocument();
 // put the acutal path to your document here
 $epgdoc->load('epg.xml');

 $xpathvar = new Domxpath($epgdoc);

 $queryResult = $xpathvar->query("//channel[@id='BHT 1']");
 foreach($queryResult as $result){
         echo $result->textContent;
 }

I think if you play around with that you can get what you need.

Upvotes: 1

Related Questions