public function begin() { $this->writer->openMemory(); $this->writer->setIndent(true); $this->writer->setIndentString(str_repeat(' ', 4)); $this->writer->startDocument('1.0', 'UTF-8'); }
public function __construct() { parent::openMemory(); //parent::startDocument(); // this hack avoids the output of the <?xml version="1.0" element parent::setIndent(true); parent::setIndentString(' '); }
function fill_muc_config_form(array $packet, array $fill_info) { $ret_val_xml = ""; $header = $packet["iq"]["@"]; $nested_conf = $packet["iq"]["#"]; $fields = $nested_conf["query"]["0"]["#"]["x"]["0"]["#"]; unset($fields["title"]); unset($fields["instructions"]); unset($nested_conf["query"]["0"]["#"]["x"]["0"]["#"]); $header["type"] = "set"; $to = $header["from"]; $header["from"] = $header["to"]; $header["to"] = $to; $nested_conf["query"]["0"]["#"]["x"]["0"]["@"]["type"] = "submit"; foreach ($fill_info as $var => $value) { if (!$this->set_field_value($fields["field"], $var, $value)) { return false; } } // var_dump($packet); // Building response array $response = array("iq" => array("@" => $header, "#" => $nested_conf)); $response["iq"]["#"]["query"]["0"]["#"]["x"]["0"]["#"] = $fields; // var_dump($response); // var_dump($header); // var_dump($nested_conf); // var_dump($fields); /*********************************** ******** Generate the XML ***********************************/ $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString(' '); // Starting roots (usualy we've got only 1 root for a pck). foreach ($response as $key => $value) { $xml->startElement($key); if (is_array($value)) { // Attributes if (is_array($value["@"])) { foreach ($value["@"] as $attr => $attr_value) { $xml->writeAttribute($attr, $attr_value); } } // Nested elements if (is_array($value["#"])) { $this->write($xml, $value["#"]); } } $xml->endElement(); $ret_val_xml = $xml->outputMemory(true); } return $ret_val_xml; // var_dump($packet); // var_dump($fill_info); }
private function initialise() { /* Setting XML header */ @header("content-type: application/vnd.google-earth.kml+xml; charset=UTF-8"); /* Initializing the XML Object */ $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString(' '); $xml->startDocument('1.0', 'UTF-8'); return $xml; }
function getXml($results) { $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); // new $xml->setIndentString(" "); // new $xml->startDocument('1.0', 'UTF-8'); $xml->startElement('root'); write($xml, $results); $xml->endElement(); $xml->endDocument(); // new $data = $xml->outputMemory(true); //$file = file_put_contents(APPPATH . '../uploads/data.xml', $data); return $data; }
function outputXml($results, $xsltPath) { /* Setting XML header */ @header("content-type: text/xml; charset=UTF-8"); /* Initializing the XML Object */ $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString(' '); $xml->startDocument('1.0', 'UTF-8'); if (isset($xsltPath)) { $xml->WritePi('xml-stylesheet', 'type="text/xsl" href="' . $xsltPath . '"'); } $xml->startElement('callback'); $xml->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->writeAttribute('xsi:noNamespaceSchemaLocation', 'schema.xsd'); /* Function that converts each array element to an XML node */ function write(XMLWriter $xml, $data) { foreach ($data as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { #The only time a numeric key would be used is if it labels an array with non-uniqe keys write($xml, $value); continue; } else { $xml->startElement($key); write($xml, $value); $xml->endElement(); continue; } } $xml->writeElement($key, $value); } } /* Calls previously declared function, passing our results array as parameter */ write($xml, $results); /* Closing last XML node */ $xml->endElement(); /* Printing the XML */ echo $xml->outputMemory(true); }
/** * Build an XML Data Set * * @param array $data * Associative Array containing values to be parsed into an XML Data Set(s) * @param string $startElement * Root Opening Tag, default data * @return string XML String containig values * @return mixed Boolean false on failure, string XML result on success */ public function buildXML($data, $startElement = 'data') { if (!is_array($data)) { $err = 'Invalid variable type supplied, expected array not found on line ' . __LINE__ . " in Class: " . __CLASS__ . " Method: " . __METHOD__; trigger_error($err); // if($this->_debug) echo $err; return false; // return false error occurred } $xml = new \XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString(' '); if ($this->version || $this->encoding) { $xml->startDocument($this->version, $this->encoding); } $xml->startElement($startElement); $this->writeEl($xml, $data); $xml->endElement(); // write end element // returns the XML results return $xml->outputMemory(true); }
public function html($mysqli_stmt) { $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString("\t"); $xml->startElement('table'); $xml->writeAttribute('class', $this->tbl_class); $xml->startElement('thead'); $xml->startElement('tr'); ////////////////////////////////// // Column Headers ///////////////////////////////// $cntcol = count($this->col_classes); $altcol = 0; foreach (array_keys($this->cols) as $th) { $xml->startElement('th'); $xml->writeAttribute('scope', 'col'); if ($this->col_classes[$altcol] != "") { $xml->writeAttribute('class', $this->col_classes[$altcol]); } $altcol = ++$altcol % $cntcol; if (substr($th, 0, 2) == "__") { $xml->text(''); } else { //Sorting $dir = "A"; if (isset($_GET["sn"]) && $_GET["sn"] == $th && $_GET["sd"] == "A") { $dir = "D"; } $xml->startElement('a'); $xml->startAttribute('href'); $xml->writeRaw(quickgrid::get_href(["sn" => $th, "sd" => $dir, "p" => 1])); $xml->endAttribute(); $xml->text($th); $xml->endElement(); //a } $xml->endElement(); //th } $xml->endElement(); //tr $xml->endElement(); //thead $xml->startElement('tfoot'); $xml->startElement('tr'); $xml->startElement('td'); $xml->writeAttribute('colspan', count($this->cols)); ////////////////////////////////// // Pager ///////////////////////////////// $last = ceil($this->row_count / $this->per_page); $length = 8; $lbound = $this->cur_page - $length / 2; $ubound = $this->cur_page + $length / 2; if ($lbound < 1) { $lbound = 1; } if ($ubound > $last) { $ubound = $last; } if ($this->cur_page != 1) { $xml->startElement('a'); $xml->startAttribute('href'); $xml->writeRaw(quickgrid::get_href(["p" => $this->cur_page - 1])); $xml->endAttribute(); $xml->text("<"); $xml->endElement(); //a } for ($i = $lbound; $i <= $ubound; $i++) { if ($i != $this->cur_page) { $xml->startElement('a'); $xml->startAttribute('href'); $xml->writeRaw(quickgrid::get_href(["p" => $i])); $xml->endAttribute(); $xml->text("{$i}"); $xml->endElement(); //a } else { $xml->startElement('span'); $xml->text("{$i}"); $xml->endElement(); //span } } if ($this->cur_page != $last) { $xml->startElement('a'); $xml->startAttribute('href'); $xml->writeRaw(quickgrid::get_href(["p" => $this->cur_page + 1])); $xml->endAttribute(); $xml->text(">"); $xml->endElement(); //a } $xml->endElement(); //td $xml->endElement(); //tr $xml->endElement(); //tfoot $xml->startElement('tbody'); ////////////////////////////////// // Table Data ///////////////////////////////// $cntrow = count($this->row_classes); $altrow = 0; $cntcol = count($this->col_classes); $altcol = 0; $result = $mysqli_stmt->get_result(); while ($row = $result->fetch_assoc()) { $xml->startElement('tr'); if ($this->row_classes[$altrow] != "") { $xml->writeAttribute('class', $this->row_classes[$altrow]); } $altrow = ++$altrow % $cntrow; foreach (array_keys($this->cols) as $th) { $xml->startElement('td'); if ($this->col_classes[$altcol] != "") { $xml->writeAttribute('class', $this->col_classes[$altcol]); } $altcol = ++$altcol % $cntcol; if (isset($this->td_formats[$th]) && is_callable($this->td_formats[$th])) { $tmp = $this->td_formats[$th]; $xml->writeRaw(call_user_func($tmp, $row)); } else { $td = $this->cols[$th]; if (isset($row[$td])) { $xml->text($row[$td]); } else { $xml->text(''); } } $xml->endElement(); //td } $xml->endElement(); //tr } $xml->endElement(); //tbody $xml->endElement(); //table return $xml->outputMemory(); }
/** * Construct the whole DCAT-AP document given an array of dump info * * @param array $data data-blob of i18n and config variables * @return string: xmldata */ function outputXml(array $data) { // Initializing the XML Object $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->setIndentString(' '); // set namespaces $xml->startDocument('1.0', 'UTF-8'); $xml->startElementNS('rdf', 'RDF', null); $xml->writeAttributeNS('xmlns', 'rdf', null, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); $xml->writeAttributeNS('xmlns', 'dcterms', null, 'http://purl.org/dc/terms/'); $xml->writeAttributeNS('xmlns', 'dcat', null, 'http://www.w3.org/ns/dcat#'); $xml->writeAttributeNS('xmlns', 'foaf', null, 'http://xmlns.com/foaf/0.1/'); $xml->writeAttributeNS('xmlns', 'adms', null, 'http://www.w3.org/ns/adms#'); $xml->writeAttributeNS('xmlns', 'vcard', null, 'http://www.w3.org/2006/vcard/ns#'); // Calls previously declared functions to construct xml writePublisher($xml, $data); writeContactPoint($xml, $data); $dataset = array(); // Live dataset and distributions $liveDistribs = writeDistribution($xml, $data, 'ld', null); if ($data['config']['api-enabled']) { $liveDistribs = array_merge($liveDistribs, writeDistribution($xml, $data, 'api', null)); } array_push($dataset, writeDataset($xml, $data, null, $liveDistribs)); // Dump dataset and distributions if ($data['config']['dumps-enabled']) { foreach ($data['dumps'] as $key => $value) { $distIds = writeDistribution($xml, $data, 'dump', $key); array_push($dataset, writeDataset($xml, $data, $key, $distIds)); } } writeCatalog($xml, $data, $dataset); // Closing last XML node $xml->endElement(); // Printing the XML return $xml->outputMemory(true); }
/** * 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; } }
/** * 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; } }