...

View Full Version : issues with simplexml_load_string/SimpleXMLElement on PHP 5.1/Linux



crmpicco
09-10-2009, 05:30 PM
This works fine under WAMP with PHP 5.3 and Windows XP on my dev machine. But on a Unix/PHP 5.1 env it doesn't. I am looking to pull out "LineNumber" and "TaxAmount" for each iteration of the loop below, for each iteration "$tax_line" is always an object of simplexml_load_string ( http://us2.php.net/manual/en/function.simplexml-load-string.php ).

$tax_line is the following object, which obviously has a type of "object".

Does anyone know how I would do this?



SimpleXMLElement Object
(
[@attributes] => Array
(
[Id] => 1
)

[LineNumber] => 1
[TaxSummary] => SimpleXMLElement Object
(
[EffectTaxRate] => 0.09752
[TaxAmount] => 24.38
[TaxBasis] => 250.00
)
)




$response_xml = simplexml_load_string($data);
$document_status = $tax_document->DocumentStatus->Success; // this can be outputted fine
$tax_lines = $tax_document->TaxLines->TaxLine;

foreach ($tax_lines as $tax_line) {

$linenumber = (string) $tax_line[0]->LineNumber;
$taxamount = (string) $tax_line[0]->TaxSummary->TaxAmount;

}


Any help would be really appreciated. Have been looking at this for ages now!

Cheers,
Picco

angst
09-10-2009, 05:57 PM
ok, so I assume that this part:



SimpleXMLElement Object
(
[@attributes] => Array
(
[Id] => 1
)

[LineNumber] => 1
[TaxSummary] => SimpleXMLElement Object
(
[EffectTaxRate] => 0.09752
[TaxAmount] => 24.38
[TaxBasis] => 250.00
)
)


is just

print_r($tax_lines)
right?

crmpicco
09-10-2009, 11:03 PM
Yes that is just a print_r of "$tax_line" from the loop. simplexml is enabled, as I put in the comments in the PHP snippet of code I can capture values from the XML using simplexml, but for some reason I can't capture everything I can on Windows.

Basically I am casting $tax_line[0]->LineNumber as a string because it is an object.

$linenumber = (string) $tax_line[0]->LineNumber;

What I can't understand is the difference between simplexml on Windows and on Linux. I can get this code working on Windows fine, but just not on Linux.

Not sure the best thing to do with this one?? Been banging my head against a wall for ages.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum