Your IP: 38.107.179.219
Differences with PHP5 and PHP4 and manipulating content of XML DOM
Posted by: Asif D. Khalyani
I just recently created a solution in php to access an XML output from a .XLS (MS Excel 2003) spreadsheet.
The problem I found was:
==> I was working locally with PHP5. And when I finished all my hard work, I uploaded the files to the webserver to find nothing but errors.
Errors were along the lines of
"Warning: domdocument::domdocument() expects at least 1 parameter, 0 given "
or
"Call to undefined function load()"
I soon found the cause to be the versions of PHP that we were using differed.
So heres my findings:
XMLDOM functions
| PHP4 | PHP5 | |
| The differences |
in php4 you need to work directly with the arrays. SEE Spec http://za.php.net/manual/en/ref.domxml.php |
In php5 you have a set of already defined functions for accessing the XML tags and values. SEE: http://nz.php.net/manual/en/ref.dom.php |
| Reading from a file | $dom = domxml_open_file("test.xml"); |
$doc = new DOMDocument(); |
| return DOMNodeList of all elements under the root node | $tagnamenodes = $dom->get_elements_by_tagname( "tagname" ); |
$tagnamenodes = $doc->getElementsByTagName( "tagname" ); |
| get the elements named element_name | $nodes = $othertagnamenodes[0]->get_elements_by_tagname( "othertagnames" ); |
$nodes = $othertagnamenodes->item(0)->getElementsByTagName( "othertagnames" ); |
| Getting the values of a tag given an array retrieved by getelementsbytagname functions. | $data = $datalist[6]->get_content(); |
$data = $datalist->item(6)->nodeValue; |
|
|


