I am using PHP 4.2.3.
I am trying to work with php and xml, specifically DomDocument->get_element_by_id.
My objective is to build xhtml pages. I have the page templates in xml files which I load into a DOM then get dynamic content from mySQL again as xml. Then I want to insert the dynamic xml content under a specific node in the base xml templates.
According to documentation (http://www.php.net/manual/en/function.domdocument-get-element-by-id.php) this function used to perform a simple xpath search but now it appears to require a DTD to define the attributes.
A simple template would look like:-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<span id="span1">
</span>
</body>
</html>
Using the xhtml dtd as per the first line DomDocument->get_element_by_id returns null. If I remove the xhtml DTD from the template and insert my own simple DTD, like:-
<!DOCTYPE html [
<!ELEMENT HTML (span)>
<!ELEMENT SPAN ANY>
<!ATTLIST span id ID #IMPLIED>
]>
I can then reference elements correctly using DomDocument->get_element_by_id. I can also use DomNode->append_child to append the dynamic content (transformed with xsl) to the span node.
THE PROBLEM:
I get a stray ]> appearing at the top of the page and the page content is not visible because the <! in the DTD are commenting out the page output. It is the same if I use an external DTD. Anyone have any ideas?
Also anyone know what happened to phpDOM?
It used to be available at: http://devil.medialab.at/projects/phpdom/doc/phpDOM.html