Using variable for tag in getElementsByTagName() for PHP and XML?

Posted by Jared on Stack Overflow See other posts from Stack Overflow or by Jared
Published on 2012-08-30T15:36:36Z Indexed on 2012/08/30 15:38 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

See my PHP:

$file = "routingConfig.xml";
    global $doc;
    $doc = new DOMDocument();
    $doc->load( $file );
$ElTag = "Route";
$tag = $doc->getElementsByTagName($ElTag);

XML is:

<Routes>
  <Route></Route>
  <Route></Route>
<Routes>

Error returned is:

Fatal error: Call to a member function getElementsByTagName() on a non-object

I'm not sure how to do this?

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml