Hallo zusammen,
ich versuche gerade zum ersten mal eine XML Datei mit SimpleXML auszulesen.
Die XML Struktur sieht wie folgt aus:
...
<DeviceOption fixed="Yes">
<!-- ############################################### -->
<feature>
<name>LargeCapacityTray</name>
<displayname>Large Capacity Tray</displayname>
<oidlength>100</oidlength>
<options>
<!-- The following values should be the raw value -->
<!-- , should not be the value by resource DLL. -->
<option value="notinstalled" optionvalue="NotInstalled" displayvalue="Not Installed" dtype="s"/>
<option value="1378" optionvalue="SKAD" displayvalue="Large Tray" dtype="s"/>
<option value="1379" optionvalue="ERIAC" displayvalue="Wide Tray" dtype="s"/>
</options>
<description>This is the Optional Large Capacity Tray</description>
</feature>
<!-- ######################################## -->
<feature>
....
</feature>
</DeviceInstallableOption>
Es gibt also mehrere Bereiche mit <feature>.
Auslesen kann ich bereits ohne Probleme die Elemente "description" und "displayname".
Interessant wären für mich aber vor allem die Bereich <options> und hier dann die einzelnen Werte bei <option>.
Ich habe es so versucht:
foreach($xml->DeviceInstallableOption[0]->feature->options as $opt){
echo $opt->option . "<br />";
}
Das bringt aber keine Ausgabe.
Wenn ich ein var_dump mache sehe ich allerdings die Werte.
var_dump($xml->DeviceInstallableOption[0]->feature->options);
Wie spreche ich diese Elemente richtig an?
$filename = 'test.xml';
if(file_exists($filename)) {
$xml = simplexml_load_file($filename);
if($xml) {
//var_dump($xml->DeviceInstallableOption[0]->feature->options);
foreach($xml->DeviceInstallableOption[0]->feature as $news) {
echo $news->description . "<br />";
echo $news->displayname . "<br />";
echo "<hr />";
}
//versuch die <option> auszulesen
foreach($xml->DeviceInstallableOption[0]->feature->options as $opt){
echo $opt->option . "<br />";
}
} else {
echo '<p>Die Datei names '. $filename .' konnte nicht geöffnet
werden</p>';
}
}//if(file_exists($filename))
vielen Dank und viele Grüße
hawk