Jump to content

simplexml problem


Guest

Recommended Posts

I wrote a script to check a remote xml file for the stock state of some products.

 

I want to list all sizes ID having "available"=true and "appearance id"=2

 

the expected result should be

 

2
3
4
5
6

 

but i'm getting

 

38
2
3
4
5
6

 

where the hell does this "38" comes from ?

 

 

Here's the script:

 

<?php
$checkstockcolor = "2";
	$apiurl = "http://api.spreadshirt.com/api/v1/shops/266497/productTypes/175";
	$feed = simplexml_load_file($apiurl);
    $producttype = $feed->productType;
    $stockstate = $feed->stockStates->stockState;
       	foreach ($stockstate as $stock) {
    		$available = $stock->available;
    		$stockcolor = $stock->appearance[id];
    		$size = $stock->size[id];
    			// garder uniquement les résultats de la couleur présentement sélectionnée
    			if ($stockcolor == $checkstockcolor && $available == "true") {
    			echo "$size<br>";
    			}
    	}
 ?>

 

 

Thank you !

Link to comment
https://forums.phpfreaks.com/topic/275142-simplexml-problem/
Share on other sites

I've got a simplexml "cheat sheet" that I keep handy because I've done a lot of work with XML. Last week, or maybe the week before, I turned the info into a blog post on my website.

 

Here is a link to the blog post: http://bit.ly/W4QWpf

 

The blog post goes over just about all of your potential parsing needs. Namespaces, attributes, etc.

Link to comment
https://forums.phpfreaks.com/topic/275142-simplexml-problem/#findComment-1416396
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.