# Fatal error: Call to undefined static function: domdocument::loadxml()

**URL:** <https://forum.kirupa.com/t/fatal-error-call-to-undefined-static-function-domdocument-loadxml/269746>\
**Category:** programming\
**Created:** [September 1, 2008, 2:23am UTC](https://forum.kirupa.com/t/fatal-error-call-to-undefined-static-function-domdocument-loadxml/269746 "2008-09-01T02:23:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![java\_ftp\_er](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@java\_ftp\_er](https://forum.kirupa.com/u/java_ftp_er)\
**Post date:** [September 1, 2008, 2:23am UTC](https://forum.kirupa.com/t/fatal-error-call-to-undefined-static-function-domdocument-loadxml/269746/1 "2008-09-01T02:23:26Z")

</div>

\<?php

//file  
$query = “technologies.txt”;

//Create the DOM Document object from the XML returned by the query  
$xml = file\_get\_contents($query);  
$dom = new DOMDocument;  
$dom = DOMDocument::loadXML($xml);

function xml\_to\_result($dom) {

//This function takes the XML document and maps it to a  
//PHP object so that you can manipulate it later.

//First, retrieve the root element for the document  
$root = $dom-\>firstChild;

//Next, loop through each of its attributes  
foreach($root-\>attributes as $attr) {  
$res[$attr-\>name] = $attr-\>value;  
}

//Now, loop through each of the children of the root element  
//and treat each appropriately.

//Start with the first child node. (The counter, i, is for  
//tracking results.  
$node = $root-\>firstChild;  
$i = 0;

//Now keep looping through as long as there is a node to work  
//with. (At the bottom of the loop, the code moves to the next  
//sibling, so when it runs out of siblings, the routine stops.  
while($node) {

```
//For each node, check to see whether it's a Result element or
//one of the informational elements at the start of the document.
switch($node-&gt;nodeName) {

  //Result elements need more analysis.
  case 'Result':
    //Add each child node of the Result to the result object,
    //again starting with the first child.
    $subnode = $node-&gt;firstChild;
    while($subnode) {

      //Some of these nodes just are just whitespace, which does
      //not have children.
      if ($subnode-&gt;hasChildNodes()){

        //If it does have children, get a NodeList of them, and
        //loop through it.
        $subnodes = $subnode-&gt;childNodes;
        foreach($subnodes as $n) {

          //Again check for children, adding them directly or
          //indirectly as appropriate.
          if($n-&gt;hasChildNodes()) {
            foreach($n-&gt;childNodes as $cn){
               $res[$i][$subnode-&gt;nodeName][$n-&gt;nodeName]=
                                          trim($cn-&gt;nodeValue);
            }
        } else {
            $res[$i][$subnode-&gt;nodeName]=trim($n-&gt;nodeValue);
          }
        }
      }
      //Move on to the next subnode.
      $subnode = $subnode-&gt;nextSibling;
    }
    $i++;
    break;
  //Other elements are just added to the result object.
  default:
    $res[$node-&gt;nodeName] = trim($node-&gt;nodeValue);
    break;
}

//Move on to the next Result of informational element
$node = $node-&gt;nextSibling;

```

}  
return $res;  
}

//First, convert the XML to a DOM object you can manipulate.  
$res = xml\_to\_result($dom);

//Use one of those “informational” elements to display the total  
//number of results for the query.  
echo "\<p\>The query returns “.$res[“totalResultsAvailable”].  
" total results The first 10 are as follows:\</p\>”;

//Now loop through each of the actual results.  
for($i=0; $i\<$res[‘totalResultsReturned’]; $i++) {

```
echo "&lt;a&gt; $res[$i]&lt;a/&gt;";
echo $res[$i]['Summary'];

echo "&lt;br /&gt;&lt;br /&gt;";

```

}

?\>

```auto
?

```

hi,  
i’ve built together the following code using ibms php guides however im getting this-Fatal error: Call to undefined static function: domdocument::loadxml()  
ive searched google etc but luck.  
any thoughts?
