本文整理汇总了PHP中DOMElement::setAttributeNode方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::setAttributeNode方法的具体用法?PHP DOMElement::setAttributeNode怎么用?PHP DOMElement::setAttributeNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::setAttributeNode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: appendSceneComponents
/**
* Add scene components
*
* @param array $components
* @return void
*/
public function appendSceneComponents(array $components)
{
foreach ($components as $component) {
/*
* Check does component has any attributes to add to scene DOM element.
* default attributes most of cases are ommited so we might not have any attributes to add
*/
if ($component->hasDOMAttributes()) {
$this->scene->setAttributeNode($component->getDOMAttr());
}
}
}
示例2: importAttribute
/**
* @param \DOMElement $parent
* @param \DOMAttr $source
*/
private function importAttribute(\DOMElement $parent, \DOMAttr $source)
{
$document = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument;
$namespaceUri = $this->getMappedNamespace($source->namespaceURI);
if (empty($namespaceUri) || empty($source->prefix)) {
$attribute = $document->createAttribute($source->localName);
} else {
$attribute = $document->createAttributeNS($namespaceUri, $source->nodeName);
}
$attribute->value = $source->value;
$parent->setAttributeNode($attribute);
}
示例3: initializeNode
/**
* Initialize a node with the readability object. Also checks the
* className/id for special names to add to its score.
*
* @param \DOMElement $node
*/
protected function initializeNode($node)
{
if (!isset($node->tagName)) {
return;
}
$readability = $this->dom->createAttribute('readability');
// this is our contentScore
$readability->value = 0;
$node->setAttributeNode($readability);
// using strtoupper just in case
switch (strtoupper($node->tagName)) {
case 'ARTICLE':
$readability->value += 15;
case 'DIV':
$readability->value += 5;
break;
case 'PRE':
case 'CODE':
case 'TD':
case 'BLOCKQUOTE':
case 'FIGURE':
$readability->value += 3;
break;
case 'SECTION':
// often misused
// $readability->value += 2;
break;
case 'OL':
case 'UL':
case 'DL':
case 'DD':
case 'DT':
case 'LI':
$readability->value -= 2 * round($this->getLinkDensity($node), 0, PHP_ROUND_HALF_UP);
break;
case 'ASIDE':
case 'FOOTER':
case 'HEADER':
case 'ADDRESS':
case 'FORM':
case 'BUTTON':
case 'TEXTAREA':
case 'INPUT':
case 'NAV':
$readability->value -= 3;
break;
case 'H1':
case 'H2':
case 'H3':
case 'H4':
case 'H5':
case 'H6':
case 'TH':
case 'HGROUP':
$readability->value -= 5;
break;
}
$readability->value += $this->getWeight($node);
}
示例4: _addAttr
/**
* Helper to add a attribute
*
* @param DOMElement $parent
* @param string $name
* @param mixed $value
*
* @return void
*/
protected function _addAttr($parent, $name, $value)
{
$parent->setAttributeNode(new DOMAttr($name, $value));
}
示例5: _setStyleAttributeValue
/**
* Style attribute gets it's own setter as it's more complex than typical
*
* @param bool $returnAttr
* @return DOMElementPlus|\DOMAttr
*/
protected function _setStyleAttributeValue($returnAttr = false)
{
if ($this->hasAttribute('style')) {
$attr = $this->getAttributeNode('style');
$attr->value = $this->_getStyleAttributeString();
} else {
$attr = new \DOMAttr('style', $this->_getStyleAttributeString());
parent::setAttributeNode($attr);
}
return $returnAttr ? $attr : $this;
}