本文整理汇总了PHP中DOMElement::replaceChild方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::replaceChild方法的具体用法?PHP DOMElement::replaceChild怎么用?PHP DOMElement::replaceChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::replaceChild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertImageData
/**
* Inserts $imageData as a child into $imageObject.
*
* Detects if $imageObject contains <office:binary-data/>. If this is the case,
* this element is replaced with the given $imageData. Otherwise,
* $imageData is added as a new child.
*
* @param DOMElement $imageObject
* @param DOMElement $imageData
*/
protected function insertImageData($imageObject, $imageData)
{
$binaryDataElems = $imageObject->getElementsByTagNameNS(ezcDocumentOdt::NS_ODT_OFFICE, 'binary-data');
if ($binaryDataElems->length === 1) {
$imageObject->replaceChild($imageData, $binaryDataElems->item(0));
} else {
$imageObject->appendChild($imageData);
}
}
示例2: SetTitre
/**
*
* @param string $titre
*/
public function SetTitre($titre)
{
$set = $this->document->createTextNode($titre);
$this->elementTitle->replaceChild($set, $this->textTitre);
$this->textTitre = $set;
// Si seulement cette fonction était implémenté...
//$this->textTitre->replaceWholeText($titre);
}
示例3: replaceChild
/**
* (PHP 5)<br/>
* Replaces a child
* @link http://php.net/manual/en/domnode.replacechild.php
* @param DOMNode $newnode <p>
* The new node. It must be a member of the target document, i.e.
* created by one of the DOMDocument->createXXX() methods or imported in
* the document by .
* </p>
* @param DOMNode $oldnode <p>
* The old node.
* </p>
* @return DOMNode The old node or false if an error occur.
*/
public function replaceChild(\DOMNode $newnode, \DOMNode $oldnode)
{
$newNode = parent::replaceChild($newnode, $oldnode);
return $newNode;
}
示例4: replaceChild
/**
* Replaces a directive.
*
* @param HTTPd_DOMElement $newnode
* @param HTTPd_DOMElement $oldnode
* @return HTTPd_DOMElement
*/
public function replaceChild(\DOMNode $newnode, \DOMNode $oldnode)
{
if ($newnode instanceof \DOMAttr || $oldnode instanceof \DOMAttr) {
throw new \DOMException("Don't call Q\\HTTPd_DOMElement::" . __FUNCTION__ . "() to replace an attribute, use setAttribute() or setAttributeNode() instead.", DOM_HIERARCHY_REQUEST_ERR);
}
if ($this->firstChild === null) {
throw new \DOMException("It's not possible to add children to {$this->nodeName} direcive.", DOM_HIERARCHY_REQUEST_ERR);
}
if (!$newnode instanceof HTTPd_DOMElement && !$newnode instanceof HTTPd_DOMComment && !$newnode instanceof \DOMText) {
throw new \DOMException("You may only add Q\\HTTPd_DOMElement, Q\\HTTPd_DOMComment and DOMText nodes to a section, not a " . get_class($newnode) . ".", DOM_HIERARCHY_REQUEST_ERR);
}
return \DOMElement::replaceChild($newnode, $oldnode);
}
示例5: extendItemAndGetChangedTime
/**
* Extends one item with the full content of the specified link
*
* @param Feed $feed
* @param DOMElement $domElement
* @param bool $useCache
* @return int
*/
private function extendItemAndGetChangedTime(Feed $feed, DOMElement $domElement, $useCache)
{
/** @var $contentNodes DOMElement[] */
$contentNodes = array();
$link = "";
$time = 0;
foreach ($domElement->childNodes as $child) {
/** @var $child DOMElement */
$name = $child->nodeName;
$value = $child->nodeValue;
if ($name == "link") {
$link = $value;
if ($link == "") {
$link = $child->getAttribute("href");
}
} else {
if (in_array($name, $this->contentNames)) {
$contentNodes[] = $child;
} else {
if (in_array($name, $this->timeNames)) {
$time = strtotime($value);
}
}
}
}
$filteredContent = $this->getFilteredContentOfUrl($feed, $link, $useCache, $time);
foreach ($contentNodes as $contentNode) {
// replace old with new content
if ($filteredContent != "") {
$newNode = $contentNode->ownerDocument->createElement($contentNode->nodeName);
$newNode->setAttribute("type", "html");
$textNode = $contentNode->ownerDocument->createTextNode($filteredContent);
$newNode->appendChild($textNode);
foreach ($contentNode->attributes as $attrName => $attrNode) {
@$newNode->setAttribute($attrName, $attrNode);
}
$domElement->replaceChild($newNode, $contentNode);
} else {
@($contentNode->nodeValue .= "\n\n<br /><br /><span style='font: #ff0000'>WARNING! Your Rss-Extender rules returned an empty string for link: " . $link . "</span>");
}
}
return $time;
}