You are here:  » correcting malformed xml - removing first line


correcting malformed xml - removing first line

Submitted by schris403 on Sat, 2009-05-02 14:09 in

Does anyone have a suggestion on how to remove the first line of the below outputted xml so Magic Parser will read it correctly? I don't have access to their php so I will need to do this on my own.

http://www.livetheaction.com/motioncode/motioncodev2list.php?export=xml

Thanks a lot for anyones help!

Chris

Submitted by support on Sat, 2009-05-02 14:24

Hi Chris,

Sure, the trick here is to read the XML into a string, and then use PHP's string functions to locate the start of the XML, and strip any preceeding text, for example:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
print_r($record);
    return 
TRUE// stop parsing
  
}
  
$url "http://www.livetheaction.com/motioncode/motioncodev2list.php?export=xml";
  
$xml file_get_contents($url);
  
$pos strpos($xml,"<?xml");
  
$xml substr($xml,$pos);
  
MagicParser_parse("string://".$xml,"myRecordHandler");
?>

However, I notice that you have been a Magic Parser user for a long time, and the string:// support was only added quite recently, so you may need to download the latest version in order to use this method.

If you have lost your registration code, drop me an email and i'll resend your code...

All the best!
David.

Submitted by schris403 on Sun, 2009-05-03 15:19

Thanks! I actually just found my registration code and downloaded the new version. I can't seem to get this to work, it says there is a error on line 4... I can't see anything wrong though, do you see anything?

Thanks again,
Chris

Submitted by support on Thu, 2009-05-07 14:22

Hi Chris,

Looks fine - could you perhaps email me the script you are using and I'll check it out for you..

Cheers,
David.