xml getting children and parents

Hello Experts, I have been trying but I cannot get it right. I have two tasks to accomplish with xml and php and I am stucked now with these two.

I am building a web page that combines xml from a third party (mercadolibre.com, an eBay clone) and my app's db. Right now I need to do two things. First, I need to display all the items that are stored in my database which are children of a given category. Second, I need to place the corresponding breadcrumbs before the current category.

This is the XML_url: http://www.mercadolibre.com.mx/jm/categsXml?as_site_id=MLM 
Let us say that my_db_table looks like this:

item_num; mercadolibre_item_num; mercadolibre_category;
1; 000000001; 9728;
2; 000000002; 7655;
3; 000000003; 123151;
4; 000000004; 39161;

So if I access the page http://www.mywebapp.com/products.php?cat_id=1658

I would like to display something like this:

Start > Computación > Tarjetas de TV // 'Tarjetas de TV' (is cat= 1658) and Computación is (is cat= 1648) which is the parent of 1658. Notice there are no grandparents in which case I would like to display before Computación.

   000000004 //from category 39161 is a child of 1658
   000000002 //from category 7655 which is a child 9728 and grandson of 1658
   000000001 //from category 1658 which is the cat being subject
   //since cat 123151 is not a sub category of 1658 I do not want to show 000000003

Please help, I am getting crazzzzy.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Beverley PortlockCommented:
So what exactly do you need help with? You've told us what you want to do but not which part of it is causing you all the trouble.
Maybe this is what you are looking for? Just pass in the cat_id.
function getChildNode($node){
	$return = array();
	foreach($node as $child){
			$return[] = $child->getAttribute('id');			
				$return = array_merge($return, getChildNode($child->childNodes));
	return $return;

$xmldoc = new DOMDocument();
$xmldoc->load($request) or die("Could not get XML data");

$item= $_REQUEST["cat_id"];
$string= '';
$parentlist= array();
$childlist= array();

if ($xmldoc->documentElement){
	$categories = $xmldoc->getElementsByTagName("categories");
	if ($categories->length!=0){
		foreach($categories as $cat){
			$category = $cat->getElementsByTagName("category");
			foreach($category as $node){
				$id= $node->getAttribute('id');
					$string= $node->getAttribute('name');
						$childlist = getChildNode($node->childNodes);
					$parent= $node->parentNode;
						$parentlist[] = $parent->getAttribute('id');
						$string = $parent->getAttribute('name')." >> ".$string;
						$parent = $parent->parentNode;
echo "Breadcrumb <br />";
echo "Start >> ".$string;
echo "<br />Parent ID";
echo "<pre>";
echo "</pre>";
echo "<br />Child ID";
echo "<pre>";
echo "</pre>";

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
degarayAuthor Commented:
100%, thanks you really made my day!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.