Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.