Пример #1
0
 /**
  * Compare two elements and their content, ignore xmlns attributes
  * Not identical, but relevant to @method isEqualNode()
  *
  * @param dom\element $element The element to compare with this one
  * @param? array $aPath The previous compared element for backtrace debug
  *
  * @return integer @const self::COMPARE_SUCCESS, @const self::COMPARE_BAD_ELEMENT, @const self::COMPARE_BAD_CHILD, @const self::COMPARE_BAD_ATTRIBUTE
  */
 public function compare(dom\node $element, $aPath = array())
 {
     $aPath[] = $this->getName();
     $this->compareBadNode = $this;
     if ($element->getType() == self::TEXT || !($this->getName() == $element->getName()) || !($this->getNamespace() == $element->getNamespace())) {
         $this->compareBadNode = $this;
         return self::COMPARE_BAD_ELEMENT;
     }
     if ($this->readAttribute('ignore', self::COMPARE_NS, false)) {
         return self::COMPARE_SUCCESS;
     }
     $attribute = self::compareAttributes($this, $element);
     if ($attribute !== true) {
         $this->compareBadNode = $attribute;
         return self::COMPARE_BAD_ATTRIBUTE;
     }
     if ($this->getChildren()->length != $element->getChildren()->length) {
         $this->compareBadNode = $this;
         return self::COMPARE_BAD_CHILD;
     } else {
         foreach ($element->getChildren() as $iKey => $child) {
             if ($selfChild = $this->getChildren()->item($iKey)) {
                 $iResult = $selfChild->compare($child, $aPath);
                 if ($iResult !== self::COMPARE_SUCCESS) {
                     if ($selfChild->getType() == self::ELEMENT) {
                         $this->compareBadNode = $selfChild->compareBadNode;
                     }
                     return self::COMPARE_BAD_CHILD;
                 }
             } else {
                 $this->compareBadNode = $this;
                 return self::COMPARE_BAD_CHILD;
             }
         }
     }
     return self::COMPARE_SUCCESS;
 }