本文整理匯總了PHP中DomDocument::insertBefore方法的典型用法代碼示例。如果您正苦於以下問題:PHP DomDocument::insertBefore方法的具體用法?PHP DomDocument::insertBefore怎麽用?PHP DomDocument::insertBefore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DomDocument
的用法示例。
在下文中一共展示了DomDocument::insertBefore方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getString
/**
* @return string
*/
public function getString()
{
// ensure the xml has the required xpacket processing instructions
$result = $this->xpath->query('/processing-instruction(\'xpacket\')');
$hasBegin = $hasEnd = false;
/** @var $item \DOMProcessingInstruction */
foreach ($result as $item) {
// do a quick check if the processing instruction contains 'begin' or 'end'
if (false !== stripos($item->nodeValue, 'begin')) {
$hasBegin = true;
} elseif (false !== stripos($item->nodeValue, 'end')) {
$hasEnd = true;
}
}
if (!$hasBegin) {
$this->dom->insertBefore($this->dom->createProcessingInstruction('xpacket', "begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\""), $this->dom->documentElement);
}
if (!$hasEnd) {
$this->dom->appendChild($this->dom->createProcessingInstruction('xpacket', 'end="w"'));
// append to end
}
// ensure all rdf:Description elements have an rdf:about attribute
$descriptions = $this->xpath->query('//rdf:Description');
for ($i = 0; $i < $descriptions->length; $i++) {
/** @var \DOMElement $desc */
$desc = $descriptions->item($i);
$desc->setAttributeNS(self::RDF_NS, 'rdf:about', $this->about);
}
return $this->dom->saveXML();
}
示例2: renderElement
/**
* Renders the element to string
* @return string
*/
public function renderElement()
{
if (isset($this->tag) && $this->tag instanceof DOMElement) {
if ($this->dom->hasChildNodes()) {
$this->dom->insertBefore($this->tag, $this->dom->firstChild);
} else {
$this->dom->appendChild($this->tag);
}
}
$out = '';
foreach ($this->dom->childNodes as $node) {
$out .= $this->dom->saveXml($node);
}
return $out;
}