Update of /cvsroot/phpxd/phpXD/include/dom
In directory usw-pr-cvs1:/tmp/cvs-serv22902/include/dom
Modified Files:
Document.php Element.php
Log Message:
Added getElementById in interface Document.
Index: Document.php
===================================================================
RCS file: /cvsroot/phpxd/phpXD/include/dom/Document.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Document.php 6 Feb 2002 23:07:51 -0000 1.3
--- Document.php 8 Feb 2002 17:48:12 -0000 1.4
***************
*** 311,316 ****
*/
function &getElementById($elementID) {
! // This could not be implemented, as long as the DTD is not parsed.
! return NOT_SUPPORTED_ERR;
}
--- 311,330 ----
*/
function &getElementById($elementID) {
! $element = null;
! if (isset($this->doctype) &&
! isset($this->doctype->elements)) {
! $element = $this->getElementByIdHelp($elementID, true,
! $this->documentElement);
! }
! else {
! $element = $this->getElementByIdHelp($elementID, false,
! $this->documentElement);
! }
! if ($element == null) {
! return NOT_FOUND_ERR;
! }
! else {
! return $element;
! }
}
***************
*** 366,369 ****
--- 380,431 ----
}
+ /**
+ * Runs recursively through the DOM-Tree and returns the element with
+ * attribute id.
+ *
+ * @private
+ * @param $tagName <code>string</code>
+ * @param $id <code>boolean</code>
+ * @param $parent <a href="Node.html">Node</a>
+ * @returns void
+ */
+ function &getElementByIdHelp($id, $dtd, &$parent) {
+ $element = null;
+ if ($parent->nodeType == ELEMENT_NODE) {
+ if (!$dtd) {
+ $attr = $parent->getAttribute("id");
+ if ($attr == $id) {
+ return $parent;
+ }
+ }
+ else {
+ $dtdElement =
+ $this->doctype->elements->getNamedItem($parent->nodeName);
+ if (isset($dtdElement) &&
+ isset($dtdElement->attributes)) {
+ for ($i = 0; $i < $dtdElement->attributes->length; ++$i) {
+ $dtdAttribute = $dtdElement->attributes->item($i);
+ if ($dtdAttribute->type == "ID") {
+ $attr = $parent->getAttribute($dtdAttribute->nodeName);
+ if ($attr == $id) {
+ return $parent;
+ }
+ }
+ }
+ }
+ }
+
+ if ($parent->hasChildNodes()) {
+ $element = $this->getElementByIdHelp($id, $dtd,
+ $parent->firstChild);
+ }
+ }
+
+ if ((isset($parent->nextSibling)) && ($element != null)) {
+ return $this->getElementByIdHelp($id, $parent->nextSibling, $result);
+ }
+ return $element;
+ }
+
/**
* Runs recursively through the DOM-Tree and returns a NodeList with all
Index: Element.php
===================================================================
RCS file: /cvsroot/phpxd/phpXD/include/dom/Element.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Element.php 6 Feb 2002 23:07:51 -0000 1.2
--- Element.php 8 Feb 2002 17:48:12 -0000 1.3
***************
*** 56,60 ****
function getAttribute($name) {
$attr =& $this->getAttributeNode($name);
! if ($attr != NOT_FOUND_ERROR) {
return $attr->getValue();
}
--- 56,60 ----
function getAttribute($name) {
$attr =& $this->getAttributeNode($name);
! if ($attr != NOT_FOUND_ERR) {
return $attr->getValue();
}
|