/**
  * @param DOMElement $element
  * @param $name
  * @param string|null|bool $default
  *
  * @return null|string
  * @throws MWException If the attribute is not found and no default is provided
  */
 private function getAttributeValue(DOMElement $element, $name, $default = false)
 {
     $node = $element->getAttributeNode($name);
     if (!$node) {
         if ($default !== false) {
             return $default;
         } else {
             throw new MWException('Required ' . $name . ' attribute not found in <' . $element->tagName . '> tag');
         }
     }
     return $node->textContent;
 }
Beispiel #2
0
 public function loadAttribute($sName, $sNamespace = '', $bDebug = true)
 {
     if ($sNamespace) {
         $result = parent::getAttributeNodeNS($sNamespace, $sName);
     } else {
         $result = parent::getAttributeNode($sName);
     }
     if (!$result && $bDebug) {
         $this->throwException(sprintf('No result for @attribute %s:%s', $sNamespace, $sName));
     }
     return $result;
 }
Beispiel #3
0
 /**
  * Get an attribute value
  *
  * @param string $name
  * @return Attribute|\DOMAttr
  */
 public function getAttributeNode($name)
 {
     list($namespace, $localName) = $this->resolveTagName($name);
     if ($namespace != '') {
         return parent::getAttributeNodeNS($namespace, $localName);
     } else {
         return parent::getAttributeNode($name);
     }
 }