本文整理汇总了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;
}