#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,689
    Rep Power
    171

    Catchable fatal error: Object of class DOMNodeList could not be converted to string


    What am I doing wrong?
    PHP Code:
    <?php $xml = new DOMDocument;
    $xml->load('test.xml');

    foreach(
    $xml->getElementsByTagname('show') as $show)
        {
            echo 
    $string $show->getElementsByTagname('Name');
        }
    ?>
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <shows>
      <show id="1">
        <Name>CNN</Name>
        <time>1 pm</time>
      </show>
      <show id="2">
        <Name>BBC</Name>
        <time>12 pm</time>
      </show>
      <show id="3">
        <Name>ABS</Name>
        <time>3.45 pm</time>
      </show>
      <show id="4">
        <Name>HBO</Name>
        <time>10 am</time>
      </show>
      <show id="5">
        <Name>Tonight's Late Nighte</Name>
        <time>Mid night</time>
      </show>
    </shows>
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    $string is not a string. It's a DOMNodeList, as the error message says. Try
    PHP Code:
    echo current($show->getElementsByTagName('Name'))->nodeValue
    or just using SimpleXML instead.

IMN logo majestic logo threadwatch logo seochat tools logo