Пример #1
0
 /**
  * @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();
 }
 /**
  * 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;
 }