Addicted Addicted - 1 year ago 94
PHP Question

Php cant reach XML element

I have this XML-File:

<hostgroup id="530">
<host id="451">
<host id="457">
<host id="463">

I want to list all host names of a hostgroup but I can't pass through the

Target is to do this in a loop, but it even didn't work without it.

The last thing I tried is this:

$xml = simplexml_load_file ('http://localhost/file.xml');
echo $xml->hostgroup[0]->members->host[0]->host_name;

Shouldn't this work? Do you have a solution? Nothing in the related topics helped me, I think it could be a problem with the id in the host tag

Answer Source

You mean like this:

$xml = simplexml_load_file('file.xml');

foreach ($xml->hostgroup[0]->members->children() as $host) {
    echo $host->host_name.'<br/>';


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download