You are here:  » Listing options


Listing options

Submitted by dougb on Wed, 2007-04-11 14:32 in

Hi

Here is the XML file I'm using: http://www.irishstore.net/xml/ys.xml

The problem I've encountered is I need show display the products with their corresponding options like:

Embroidered Ireland
Color = White
Size = L

Six Nations Rugby Shirt
Size = L

This is as far as I've got:

<?
require("MagicParser.php");
function myRecordHandler($record) {
    $i = 0;
    while(1) {
      if ($i) $postfix = "@".$i;
      if (!isset($record["ITEM".$postfix])) break;
      $name = $record["ITEM/DESCRIPTION".$postfix];
echo $name;"<br><br>";
    $i++;
    }
}
 MagicParser_parse("ys.xml","myRecordHandler","xml|ORDERLIST/ORDER/");
?>

Any help would be great. Thanks, Doug

Submitted by support on Mon, 2007-04-16 08:41

Hi Doug,

To access the order items, the order XML needs to be parsed using the following format string:

xml|ORDERLIST/ORDER/ITEM/

This format string separates out the items individually, and you can then use the code almost as in your example to access the multiple options. Here is the code the running on my server:

http://www.magicparser.com/examples/ys.php

Here is the source:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    echo 
"<p>";
    
$name $record["DESCRIPTION"];
    echo 
$name."<br>";
    
$i 0;
    while(
1)
    {
      if (
$i$postfix "@".$i;
      if (!isset(
$record["OPTION".$postfix])) break;
      
$optionName $record["OPTION".$postfix."-NAME"];
      
$optionValue $record["OPTION".$postfix];
      echo 
$optionName." = ".$optionValue."<br>";
      
$i++;
    }
    echo 
"</p>";
  }
  
MagicParser_parse("ys.xml","myRecordHandler","xml|ORDERLIST/ORDER/ITEM/");
?>

If you want to access higher level order information, I would suggest parsing the file separately using xml|ORDERLIST/ORDER/ as the format string and accessing the order information there. However, if there are multiple orders in the file then this could become more complicated and we would need to look at using a single parse to access all item information. Let me know if you need help with this, and if possible provide a sample XML document that contains an example of multiple orders...

Hope this helps!
Cheers,
David.

Submitted by dougb on Mon, 2007-04-16 15:01

That's great - thanks for help (again)!