xml in php

My xml feed looks like the following:

$html = “”;
$url = “http://www.kevro.co.za/rss/products.aspx?email=xxxxx&password=xxxxx&feed=product”;
$xml = simplexml_load_file($url);
for($i = 0; $i < 5; $i++) {
$id = $xml->product[$i]->id;
$categorygroup = $xml->product[$i]->categorygroup;
$category = $xml->product[$i]->category;
$group = $xml->product[$i]->group;
$name = $xml->product[$i]->name;
$code = $xml->product[$i]->code;
$description = $xml->product[$i]->description;
$thumb = $xml->product[$i]->thumb;
$html .= “

$id
$categorygroup
$category
$group
$name
$code

$description

$thumb
”;

I need to be extract values from $categorygroup = “Clothing” or “Gifting” or “Sports Brands”
I also need extract values from $group = “Active Wear” or “Tracksuit” or “T Shirt”, etc…

Please if anyone could help me with this, it would be greatly appreciated.
Kind regards
Dean Menzies
[email protected]

Well, if you are using PHP5 or higher, you can use SimpleXML which is part of it.

Here is a link to explain it’s usage. As you will see, it is very easy to pull data from XML files using these commands.

If you look at example#3, you will see how to pull “CHILDREN” nodes from the XML files. A “CHILD” in XML means a sub-node. So, you have a node and then you have many children inside that node. Each is a separate node as far as I see in your XML example layout. Therefore, all of them are children of the node.

I think that makes sense. Hope you understand it. Here is the link to the tutorial on it:
http://www.w3schools.com/php/php_xml_simplexml.asp
(I use this site often to explain processes as they have simple easy to understand explanations on jus about everything!)

Good luck, let us know if you can’t figure it out.

Sponsor our Newsletter | Privacy Policy | Terms of Service