Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    387

    SimpleXML: come accedere agli @attributes?

    Ciao a tutti e scusate la domanda, ho provato a googlare un po' senza troppo successo...
    Dato un array simile:

    Codice PHP:
    SimpleXMLElement Object
    (
        [
    station] => SimpleXMLElement Object
            
    (
                [@
    attributes] => Array
                    (
                        [
    id] => 5550
                        
    [co] => IN
                        
    [co_name] => Indipendente
                        
    [lat] => 42.1183
                        
    [lng] => 12.5889
                        
    [name] => Osvaldo
                        
    [address] => Via Claudia 32
                        
    [street_code] => SS4
                        
    [highway] => O
                        
    [zip] => 00060
                        
    [city] => B649
                        
    [city_name] => Capena
                        
    [provincia] => RM
                        
    [fuels] => bde
                        
    [phone] => +39 069080505
                        
    [status] => AP
                        
    [neighbour_distance] => 0.213
                        
    [insertion_date] => 2007-03-17 17:33
                        
    [last_updated] => 2012-07-05 00:00
                        
    [highres] => 0
                        
    [photos] => 4
                        
    [tags] => 
                        [
    user] => ferrobayer
                    
    )

                [
    reports] => SimpleXMLElement Object
                    
    (
                        [
    report] => Array
                            (
                                [
    0] => SimpleXMLElement Object
                                    
    (
                                        [@
    attributes] => Array
                                            (
                                                [
    price] => 1.719
                                                
    [date] => 2012-07-02 08:31:12
                                                
    [service] => CS
                                                
    [fuel] => benzina
                                            
    )

                                    )

                                [
    1] => SimpleXMLElement Object
                                    
    (
                                        [@
    attributes] => Array
                                            (
                                                [
    price] => 1.609
                                                
    [date] => 2012-07-05 08:08:48
                                                
    [service] => ??
                                                [
    fuel] => diesel
                                            
    )

                                    )

                                [
    2] => SimpleXMLElement Object
                                    
    (
                                        [@
    attributes] => Array
                                            (
                                                [
    price] => 1.619
                                                
    [date] => 2012-07-05 21:19:17
                                                
    [service] => CS
                                                
    [fuel] => diesel
                                            
    )

                                    )

                            )

                    )

            )


    Mi trovo in difficoltà ad accedere ai vari elementi dell'array, sopratutto il primo @attributes (non mi è mai servito ed invece stavolta si) e quelli sotto i report...

    Chiedo umilmente consiglio ed aiuto.... grazie mille in anticipo!

  2. #2
    Utente di HTML.it L'avatar di gianiaz
    Registrato dal
    May 2001
    Messaggi
    8,027

    Re: SimpleXML: come accedere agli @attributes?

    Originariamente inviato da webtemplum
    Ciao a tutti e scusate la domanda, ho provato a googlare un po' senza troppo successo...
    Dato un array simile:
    prima di tutto, quello che riporti è un oggetto, non un array.

    Immaginando che tu abbia stampato la variabile $xml, per accedere all'id di station 550:

    Codice PHP:
    $attributi $xml->station->attributes();
    echo 
    $attributi['id']; 
    Vedi qui:

    http://php.net/manual/en/simplexmlel...attributes.php

    Ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    387
    Grazie mille!
    Risolto un bel problemino (ed imparata una cosa nuova!)
    Grazie ancora!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.