I'd like to have DomDocuments meths and props available to DomXml and DomXhtml in the same instance, but I can't extend DomDomcument because I need DomIplementation to create the DomDocument intance. If I don't use DomImplementation I can't get my docs to validate, wich also disables the use of getElementById.
I thought about creating a local instance of both DomDocument and DomImplementation made avialable to DomXhtml by way of a public prop, but that's very inconvenient.
Accessing of DomDocument methods by way of a DomXml or DomXhtml instance would look very patchy, unless I define a custom method within DomXml for each one I plan on using. The latter seems very inefficient.
Example:
<?php
class DomXml {
public $domDoc;
function __construct($rootName,$publicId,$systemId) {
$domImpl = new DOMImplementation;
$docType = $domImpl->createDocumentType($rootName,$publicId,$systemId);
$this->domDoc = $domImpl->createDocument('', $rootName, $docType);
}
public function getElementById($id) {
return $this->domDoc->getElementById($id);
}
}
//Usage
$doc = new DomXml('test','Test XML File','DTD/test.dtd');
//Option 1:
$nodes = $doc->domDoc->getElementsByTagname('testtag');
//Option 2:
$node = $doc->getElementById('testnode');
?>
I can't say I like either of these options. :queasy:
If you can think of something better, please let me know.