You are here:  » Fetch data depending on type number


Fetch data depending on type number

Submitted by Event on Sun, 2007-04-22 13:28 in

Hello!

I have what I think is a pretty easy question. I would like to fetch data from the "name" tag of the following XML document. The problem is that i don't want to include any data from items of type 1, they should be excluded.

Any suggestions?

This is my code:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($item)
  {
    print 
"<li><p>".$item["NAME"]."</p></li>";
  }
  
MagicParser_parse("document.xml","xml|CONTAINER/ITEM/");
?>

This is the XML document

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <container>
- <item>
  <url>http://fc.lund.humanusgymn.se/aktuellt/FOV1-0004AB2F/</url>
  <type>1</type>
  <subtype>0</subtype>
  <name>Testing 1</name>
  </item>
- <item>
- <item>
  <url>http://fc.lund.humanusgymn.se/aktuellt/FOV1-0004AB2F/</url>
  <type>3</type>
  <subtype>0</subtype>
  <name>Testing 2</name>
  </item>
- <item>
  <url>http://fc.lund.humanusgymn.se/aktuellt/FOV1-0004AB2F/</url>
  <type>3</type>
  <subtype>0</subtype>
  <name>Testing 3</name>
  </item>
</container>

Submitted by support on Sun, 2007-04-22 18:19

Hi,

All you need to do is return from your record handler function if the TYPE field is 1 - something like this:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($item)
  {
    if (
$item["TYPE"] == 1) return;
    print 
"<li><p>".$item["NAME"]."</p></li>";
  }
  
MagicParser_parse("document.xml","xml|CONTAINER/ITEM/");
?>

Hope this helps!
Cheers,
David.