예제 #1
0
 public function close()
 {
     for ($i = 0; $i < $this->openElements; $i++) {
         $this->writer->endElement();
     }
     $this->openElements = 0;
     $this->writer->endDocument();
 }
예제 #2
0
 public function outputSitemap(Kwf_Component_Data $page)
 {
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('urlset');
     $xml->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     foreach (array_unique($this->_getSitemap($page)) as $url) {
         $xml->startElement('url');
         $xml->writeElement('loc', $url);
         $xml->endElement();
     }
     $xml->endElement();
     $xml->endDocument();
     header('Content-Type: text/xml; charset=utf-8');
     echo $xml->outputMemory(true);
     exit;
 }
예제 #3
0
 public function flush()
 {
     $this->cursor->endDocument();
     return $this->cursor->flush();
 }
예제 #4
0
 /**
  * Generates the XML output and saves it to a file or returns it as a string
  *
  * @return null|int Returns the number of bytes written to a local file or false on failure
  */
 protected function generate()
 {
     $w = new \XmlWriter();
     $w->openMemory();
     $w->setIndent(true);
     $w->setIndentString("    ");
     $w->startDocument('1.0', 'utf-8');
     $w->startElement($this->rootname);
     $row = $this->getRow();
     $keys = array_keys($row);
     foreach ($keys as $key) {
         $this->isValidName($key);
     }
     do {
         $w->startElement($this->rowname);
         foreach ($row as $key => $value) {
             if ($this->suppress && in_array($key, $this->suppress)) {
                 continue;
             }
             if ($this->hasChildren && in_array($key, $this->hasChildren)) {
                 $stripped = $this->stripHtml($value);
                 $w->startElement($key);
                 foreach ($stripped as $para) {
                     $w->writeElement('p', $para);
                 }
                 $w->endElement();
             } else {
                 $w->writeElement($key, $value);
             }
         }
         $w->endElement();
     } while ($row = $this->getRow());
     $w->endElement();
     $w->endDocument();
     $this->xml = $w->outputMemory();
     // write to file
     if (isset($this->filename) && $this->local) {
         $success = file_put_contents($this->filename, $this->xml);
         return $success;
     } elseif (isset($this->filename) && $this->download) {
         $this->outputHeaders();
         file_put_contents('php://output', $this->xml);
         exit;
     }
 }
예제 #5
0
 /**
  * Generates the XML output and saves it to a file or returns it as a string
  *
  * @return null|int Returns the number of bytes written to a local file or false on failure
  */
 protected function generate()
 {
     $w = new \XmlWriter();
     $w->openMemory();
     $w->setIndent(true);
     $w->setIndentString("    ");
     $w->startDocument('1.0', 'utf-8');
     $w->startElement($this->rootname);
     while ($object = $this->getRow()) {
         // Start a new row for each object
         $w->startElement($this->rowname);
         foreach ($object as $key => $value) {
             if ($this->suppress && in_array($key, $this->suppress)) {
                 continue;
             }
             $this->isValidName($key);
             // Check if the key contains another object
             if (is_object($value)) {
                 // Start parent element containing rows of each object
                 $w->startElement($key . "s");
                 // $value is an array of objects
                 foreach ($value as $obj) {
                     $w->startElement($key);
                     foreach ($obj as $field => $val) {
                         $this->isValidName($key);
                         $w->writeElement($field, $val);
                     }
                     $w->endElement();
                 }
                 $w->endElement();
             } else {
                 // Write each object's property->value as <key>value</key>
                 if ($this->hasChildren && in_array($key, $this->hasChildren)) {
                     $stripped = $this->stripHtml($value);
                     $w->startElement($key);
                     foreach ($stripped as $para) {
                         $w->writeElement('p', $para);
                     }
                     $w->endElement();
                 } else {
                     $w->writeElement($key, $value);
                 }
             }
         }
         $w->endElement();
     }
     $w->endElement();
     $w->endDocument();
     $this->xml = $w->outputMemory();
     // write to file
     if (isset($this->filename) && $this->local) {
         $success = file_put_contents($this->filename, $this->xml);
         return $success;
     } elseif (isset($this->filename) && $this->download) {
         $this->outputHeaders();
         file_put_contents('php://output', $this->xml);
         exit;
     }
 }
예제 #6
0
 /**
  * The parameter is merely to comply with PHP's notion that I am
  * overriding the parent's flush, so I should provide the same
  * signature. Nor am I not, but, even if I was, PHP should allow
  * different signatures, i.e., enable both methods to be called...
  *
  * @see XMLWriter::flush()
  */
 public function flush($empty = true)
 {
     parent::endDocument();
     return parent::flush($empty);
 }