[PHP] Handling SimpleXMLElements

2007-01-11 Thread Satyam

I have a problem trying to handle SimpleXml objects.  Though I can manage
some workaround the problem, I would like to understand it better.

This is a section of the XML file I'm trying to read (it is not complete,
just a section)

 tr
   tdBERMUDA/td
   tdBermudian Dollar (customarily
 known as Bermuda Dollar) /td
   tdBMD/td
   td060/td
 /tr
 tr
   tdBHUTAN/td
   td
 pIndian Rupee/p
 pNgultrum/p
   /td
   td
 pINR/p
 pBTN/p
   /td
   td
 p356/p
 p064/p
   /td
 /tr

It is part of a table with currency codes.   Each row has 4 cells containing
the country name, the currency description, the currency code and the
numeric code, as seen in the first row.  Nevertheless, with countries that
have more than one currency, it still has a single row with the first cell
containing the country name (see BHUTAN) but then in the following cells it
has several lines, one for each currency, as simple paragraphs.

When I get to the row for BHUTAN, I do a foreach to see what's in each cell.
Function dump() just does a var_dump() of whatever is given in the first
argument within a pre tag and uses the second argument as a heading,
surrounded by dashes.  In this case I copied the expression of what I am
dumping as the title (within single quotes so it does not expand).

 foreach($row as $cell) {
   dump($cell,'$cell);
   dump($cell-p,'$cell-p');
   dump((array)$cell-p,'(array)$cell-p');
   dump($cell-p[1],'$cell-p[1]');
  }

The section in question is shown below.  Though $cell is shown as a
SimpleXMLElement containing one 'p' property which contains an array of two
elements:
$cell-
object(SimpleXMLElement)#8 (1) {
 [p]=
 array(2) {
   [0]=
   string(12) Indian Rupee
   [1]=
   string(8) Ngultrum
 }
}


If I dump that 'p' element, I don't get an array but an object with just
one element, the first value in the array
$cell-p-
object(SimpleXMLElement)#7 (1) {
 [0]=
 string(12) Indian Rupee
}


If I typecast it to an array, I still get a single element
(array)$cell-p-
array(1) {
 [0]=
 string(12) Indian Rupee
}

Nevertheless, if I explicitly index into the 'p' element, without even
typecasting it into an array, the second element is there.
$cell-p[1]-
object(SimpleXMLElement)#10 (1) {
 [0]=
 string(8) Ngultrum
}


So, now you see it, now you don't, or do you?  What's happening?

Satyam

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Handling SimpleXMLElements

2007-01-11 Thread Jochem Maas
I'm guessing you have php5.0.x running - you really want a php5.1.x
version if your going to use XML - it will avoid *alot* headaches with
regarding to using var_dump() (or print_r() or even echo) to figure out
what the simpleXML objects are/contain.

Satyam wrote:
 I have a problem trying to handle SimpleXml objects.  Though I can manage
 some workaround the problem, I would like to understand it better.
 



 cell.
 Function dump() just does a var_dump() of whatever is given in the first
 argument within a pre tag and uses the second argument as a heading,
 surrounded by dashes.  In this case I copied the expression of what I am
 dumping as the title (within single quotes so it does not expand).
 
  foreach($row as $cell) {
dump($cell,'$cell);
dump($cell-p,'$cell-p');
dump((array)$cell-p,'(array)$cell-p');
dump($cell-p[1],'$cell-p[1]');
   }
 
 The section in question is shown below.  Though $cell is shown as a
 SimpleXMLElement containing one 'p' property which contains an array of two
 elements:
 $cell-
 object(SimpleXMLElement)#8 (1) {
  [p]=
  array(2) {
[0]=
string(12) Indian Rupee
[1]=
string(8) Ngultrum
  }
 }
 
 
 If I dump that 'p' element, I don't get an array but an object with just
 one element, the first value in the array
 $cell-p-
 object(SimpleXMLElement)#7 (1) {
  [0]=
  string(12) Indian Rupee
 }
 
 
 If I typecast it to an array, I still get a single element
 (array)$cell-p-
 array(1) {
  [0]=
  string(12) Indian Rupee
 }
 
 Nevertheless, if I explicitly index into the 'p' element, without even
 typecasting it into an array, the second element is there.
 $cell-p[1]-
 object(SimpleXMLElement)#10 (1) {
  [0]=
  string(8) Ngultrum
 }
 
 
 So, now you see it, now you don't, or do you?  What's happening?
 
 Satyam
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Handling SimpleXMLElements

2007-01-11 Thread Satyam
- Original Message - 
From: Jochem Maas [EMAIL PROTECTED]




I'm guessing you have php5.0.x running - you really want a php5.1.x


PhpInfo reports it's 5.2.0 so I'm covered there.


version if your going to use XML - it will avoid *alot* headaches with
regarding to using var_dump() (or print_r() or even echo) to figure out
what the simpleXML objects are/contain.

Satyam wrote:

I have a problem trying to handle SimpleXml objects.  Though I can manage
some workaround the problem, I would like to understand it better.






cell.
Function dump() just does a var_dump() of whatever is given in the first
argument within a pre tag and uses the second argument as a heading,
surrounded by dashes.  In this case I copied the expression of what I am
dumping as the title (within single quotes so it does not expand).

 foreach($row as $cell) {
   dump($cell,'$cell);
   dump($cell-p,'$cell-p');
   dump((array)$cell-p,'(array)$cell-p');
   dump($cell-p[1],'$cell-p[1]');
  }

The section in question is shown below.  Though $cell is shown as a
SimpleXMLElement containing one 'p' property which contains an array of 
two

elements:
$cell-
object(SimpleXMLElement)#8 (1) {
 [p]=
 array(2) {
   [0]=
   string(12) Indian Rupee
   [1]=
   string(8) Ngultrum
 }
}


If I dump that 'p' element, I don't get an array but an object with just
one element, the first value in the array
$cell-p-
object(SimpleXMLElement)#7 (1) {
 [0]=
 string(12) Indian Rupee
}


If I typecast it to an array, I still get a single element
(array)$cell-p-
array(1) {
 [0]=
 string(12) Indian Rupee
}

Nevertheless, if I explicitly index into the 'p' element, without even
typecasting it into an array, the second element is there.
$cell-p[1]-
object(SimpleXMLElement)#10 (1) {
 [0]=
 string(8) Ngultrum
}


So, now you see it, now you don't, or do you?  What's happening?

Satyam





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php