Hallo mede Tweakers,
Ik heb een probleem waar ik niet uit kom.
Ik laad met de PHP functie 'simplexml_load_file' een XML bestand.
De waarden uit dit bestand wil ik ga koppelen aan variabelen.
XML bestand:
Als ik de timestamp wil pakken gebruik ik de volgende code:
Dit werk prima! maar hoe kom ik nou een niveau lager?
Het zijn volgens mij objecten in objecten? Dit is de output van een print_r
Alvast bedankt voor de reactie
Ik heb een probleem waar ik niet uit kom.
Ik laad met de PHP functie 'simplexml_load_file' een XML bestand.
De waarden uit dit bestand wil ik ga koppelen aan variabelen.
XML bestand:
code:
1
2
3
4
5
6
7
8
9
| <?xml version="1.0" encoding="UTF-8"?> -<variable-set now="1337947409324" time="2012-05-25 08:03:29" timestamp="1337947409310"> +<variable classpath="/nbAlertSchedInfo" class="nbAlertSchedInfo" varid="nbAlertSched"> +<variable classpath="/nbEnclosure" class="nbEnclosure" varid="nbBaseEnclosure" guid="B06504c_nbBaseEnclosure"> +<variable classpath="/nbIPInterfaceStatus" class="nbIPInterfaceStatus" varid="nbIPInterface_eth0_status" guid="B06504c_nbIPInterface_eth0_status"> +<variable classpath="/nbConfigUpdTimeCls" class="nbConfigUpdTimeCls" varid="nbConfigUpdTime" guid="B06504c_nbConfigUpdTime"> +<variable classpath="/nbErrorCond" class="nbErrorCond" varid="nbErrorCond_56FE3CD5" guid="B06504c_nbErrorCond_56FE3CD5"> +<variable classpath="/nbEnclosure/nbSNMPEnclosure" class="nbSNMPEnclosure" varid="nbSNMPEnc0982AC62" guid="B06504c_nbSNMPEnc0982AC62"> +<variable classpath="/nbAlertProfile" class="nbAlertProfile" varid="nbAlertProfile_default" guid="B06504c_nbAlertProfile_default">- </variable-set> |
Als ik de timestamp wil pakken gebruik ik de volgende code:
code:
1
2
3
4
| <?php
$xml = simplexml_load_file('bestand.xml');
print $xml['timestamp'];
?> |
Dit werk prima! maar hoe kom ik nou een niveau lager?
Het zijn volgens mij objecten in objecten? Dit is de output van een print_r
code:
1
| SimpleXMLElement Object ( [@attributes] => Array ( [timestamp] => 1337947409310 [time] => 2012-05-25 08:03:29 [now] => 1337947409324 ) [variable] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [varid] => nbAlertSched [class] => nbAlertSchedInfo [classpath] => /nbAlertSchedInfo ) [nls-string-val] => 0640354466 ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [varid] => nbBaseEnclosure [guid] => B06504c_nbBaseEnclosure [class] => nbEnclosure [classpath] |
Alvast bedankt voor de reactie
M3 LR Black/Black/Aero/Trekhaak - Bestelling 1-10 PonLease, RN 19-10, VIN 20-11, Leverdatum: 10-12-2019