PHP Classes

problem with 1 level

Recommend this page to a friend!

      SimpleXML for PHP4  >  All threads  >  problem with 1 level  >  (Un) Subscribe thread alerts  
Subject:problem with 1 level
Summary:Cannot see a level when it contains only one item
Messages:4
Author:regis loumont
Date:2012-08-21 15:53:11
Update:2012-08-22 08:33:12
 

  1. problem with 1 level   Reply   Report abuse  
Picture of regis loumont regis loumont - 2012-08-21 15:53:11
Hello
great package thank you. As I am still using an old web server I found your very usefull work. I am a bit stuck when trying to parse one level of the following file http://www.honda.fr/car/content/data/dms/gamme_fh.xml.
when using this code:
$details = array(); // init array for return values
$sx = new simplexml;
$sx->ignore_level=1;
$feed = $sx->xml_load_file($filename,"array");
foreach ($feed as $modeleinfo)
{if ($modeleinfo[ModelName] == $modele)
{
foreach ($modeleinfo[Version] as $versioninfo)
{
if ($versioninfo[VersionDescription] == $version)
{
foreach ($versioninfo[VersionsRefs][VersionRef] as $versionreference)
{
$minech = $minech.$versionreference[Mine].",";
$mineref = $versionreference[Mine];
}
...
if the level VersionRef contains only one set of elements (MTO and Mine) then the instruction foreach does not return the correct value in $mineref, while it does if there are multiple elements.

I have used your code to display the whole file as you can try in http://www.honda.fr/wshonda/calltest.php
and it works fine.
Any idea?
thank you for your help and the nice work which was very usefull
Regards
Regis

  2. Re: problem with 1 level   Reply   Report abuse  
Picture of regis loumont regis loumont - 2012-08-21 17:19:57 - In reply to message 1 from regis loumont
ok
this has nothing to do with the package. I found on some forum that it is sometimes necessary to test if there is only one set of data: here is the code I used if it is useful for someone:
$versionreference = $versioninfo[VersionsRefs][VersionRef];
$nbarray = $versionreference[0];
$mine_count = count($nbarray);
if($mine_count == 0) // if $minecount == 0 there is one level only
{
code continuing ...
regards

Regis

  3. Re: problem with 1 level   Reply   Report abuse  
Picture of Taha Paksu Taha Paksu - 2012-08-21 17:29:05 - In reply to message 2 from regis loumont
you can check it with

* if(is_array($nbarray)){
*
* // foreach
*
* }else{
*
* // single item
*
* }

Regards.

  4. Re: problem with 1 level   Reply   Report abuse  
Picture of regis loumont regis loumont - 2012-08-22 08:33:12 - In reply to message 1 from regis loumont
Thanks for the tip, it works fine. you are really good !
and also thanks for taking the time to consider my problem, that's so kind
Regis