Really complex XML
Submitted by nigel on Wed, 2008-04-23 20:00.Magic Parser
Hello,
Take a look at:
http://www.cuedev.co.uk/data.xml
I am running it through your parser fine and can get the data from the <hl1> node but I also need the data from <body.content> but, as you will see in the XML, the <p> tags are being picked up as nodes so are appearing in the array as separate values. I though I could loop through $record['body.content'] but it's not picking this up as an array? What am I doing wrong?
Your advise would be appreciated.
Cheers
Hello,
Thanks David that was spot on.
Cheers,
Hi Nigel,
As these fields are duplicated within the XML, Magic Parser is resolving them by appending @1, @2... etc. to each additional element of the same name at the level at which you are parsing.
There are various ways to deal with this, but what I would do in this situation is to loop through $record and concatenate any fields that are part of the split-up parts that you want by comparing the first n characters of the key, and then using the value if it matches. For example:
<?phpfunction myRecordHandler($record)
{
$body.content = "";
foreach($record as $key => $value)
{
if (strpos($key,"NEWSCOMPONENT/NEWSCOMPONENT/CONTENTITEM/DATACONTENT/NITF/BODY/BODY.CONTENT")===0)
{
$body.content .= $value." ";
}
}
print $body.content; // or use however you want
}
?>
In this case, the resulting content won't have any P tags; but you could easy replicate what the feed is attempting to convey by combining the values within P tags, so instead of:
$body.content .= $value." ";(where each value would be spearated by a space)... you could use:
$body.content .= "<p>".$value."</p>";Let me know if you need any more info or a fuller example...
Cheers,
David.