xpath php attributes not working?
- by Jared
Getting this error Call to a member function attributes() on a non-object
I have found multiple answers to this on SO, but none of them seem to solve my problem?
Here is the XML:
<Routes>
    <Route type="source" name="incoming">
    </Route>
<Routes>
Here is the PHP:
$doc = new SimpleXMLElement('routingConfig.xml', null, true);
class traverseXML {
    function getData() {
        global $doc;
        $routeCount = count($doc -> xpath("Route")); //this value returns correctly
        $routeArr = array();
        for ($i = 1; $i <= $routeCount; $i++) {
            $name = $doc -> Route[$i] -> attributes() -> name;
            array_push($routeArr, $name);
        }
        return $routeArr;
    }
    }
    $traverseXML = new traverseXML;
    var_dump($traverseXML -> getData());
I understand what the error means, but how is it a non-object? How do I return the name attribute of Routes/Route[1] ?