Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question issues with simplexml_load_string/SimpleXMLElement on PHP 5.1/Linux

    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/functio...oad-string.php ).

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

    Does anyone know how I would do this?

    Code:
    SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [Id] => 1
            )
    
        [LineNumber] => 1
        [TaxSummary] => SimpleXMLElement Object
            (
                [EffectTaxRate] => 0.09752
                [TaxAmount] => 24.38
                [TaxBasis] => 250.00
            )
    )
    PHP Code:

    $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

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, so I assume that this part:

    Code:
    SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [Id] => 1
            )
    
        [LineNumber] => 1
        [TaxSummary] => SimpleXMLElement Object
            (
                [EffectTaxRate] => 0.09752
                [TaxAmount] => 24.38
                [TaxBasis] => 250.00
            )
    )
    is just
    Code:
    print_r($tax_lines)
    right?

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,097
    Thanks
    15
    Thanked 1 Time in 1 Post
    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.
    PHP Code:
    $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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •