You are here:  » Problem parsing specific xml


Problem parsing specific xml

Submitted by nektar on Tue, 2012-09-11 09:28 in

Hi.

I cannot parse the following xml properly

{link saved}

Attributes are not properly by magicparser.

I'm trying to process it with string xml|DRAWRANGE/BETGAMES/

Thank you.

Submitted by support on Tue, 2012-09-11 10:27

Hi nektar,

XML documents with multiple repeating child elements at the parsing level are not ideally suited to Magic Parser but there are various pattens that make it straight forward to loop through each repeating element by using the @1, @2... @n postfix that Magic Parser uses to resolve duplicates.

In this example, parsing at the level DRAWRANGE/BETGAMES/ the following record handler function will display each property/property ID value, and each code element...

function myRecordHandler($record)
{
  $i = 0;
  $p = "";
  print "<table>";
  print "<tr><th>ID</th><th>Property</th></tr>";
  while(1)
  {
    if ($i) $p = "@".$i;
    if (!isset($record["PROPERTIES/PROP".$p])) break;
    $property = $record["PROPERTIES/PROP".$p];
    $propertyId = $record["PROPERTIES/PROP".$p."-ID"];
    print "<tr><td>".$propertyId."</td><td>".$property."</td></tr>";
    $i++;
  }
  print "</table>";
  $i = 0;
  $p = "";
  print "<table>";
  print "<tr><th>CODE</th><th>DSC</th><th>ODD</th><th>STATUS</th><th>MIN</th><th>MAX</th></tr>";
  while(1)
  {
    if ($i) $p = "@".$i;
    if (!isset($record["CODES".$p])) break;
    $code = $record["CODES".$p."-CODE"];
    $dsc = $record["CODES".$p."-DSC"];
    $odd = $record["CODES".$p."-ODD"];
    $status = $record["CODES".$p."-STATUS"];
    $min = $record["CODES".$p."-MIN"];
    $max = $record["CODES".$p."-MAX"];
    print "<tr><td>".$code."</td><td>".$dsc."</td><td>".$odd."</td><td>".$status."</td><td>".$min."</td><td>".$max."</td></tr>";
    $i++;
  }
  print "</table>";
}

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by nektar on Fri, 2012-09-14 07:00

Thank you for you answer.

At first, everything seemed to work fine. But as the xml source file became bigger not all records are parsed by the parser.
Is there a specific limit in number of records that can be passed? If yes, how can we overcome this?

For example this record is not parsed at all:

betGames id="161944"

Please let me know if you need the link of the xml file again.

Thank you.

Submitted by support on Fri, 2012-09-14 07:36

Hi,

There is no limit within Magic Parser at all but it may be that you're reaching the PHP max execution time on your server. First of all, try adding on the first line of your script:

  set_time_limit(0);

...your script should then be able to run to completion..

Hope this helps,
Cheers,
David.

Submitted by nektar on Fri, 2012-09-14 07:39

Saving the xml file locally on my server did the trick.

It doesn't work reading it directly from remote location.

That is however ok. I can first copy the file and then read it.

Thank you.