public function addHeader($type, $hasFeeds = false) { $this->writer->startElement($type); $this->writer->writeAttribute('xmlns', "http://www.sitemaps.org/schemas/sitemap/0.9"); if ($hasFeeds) { $this->writer->writeAttribute('xmlns:image', "http://www.google.com/schemas/sitemap-image/1.1"); $this->writer->writeAttribute('xmlns:video', "http://www.google.com/schemas/sitemap-video/1.1"); } $this->writer->endAttribute(); $this->openElements++; return $this; }
/** * writeChannel writes a Core\Channel instance feed. * * @param Channel $channel * * @return mixed Similar to XMLWriter::flush * * @see http://php.net/manual/function.xmlwriter-flush.php */ public function writeChannel(Channel $channel) { $this->xmlWriter->startDocument(); if ($this->flushEarly) { $this->xmlWriter->flush(); } $this->xmlWriter->startElement('rss'); foreach ($this->namespaces as $ns => $url) { $this->xmlWriter->writeAttribute(sprintf('xmlns:%s', $ns), $url); } $this->xmlWriter->writeAttribute('version', '2.0'); $this->writeObject($channel); $this->xmlWriter->endElement(); return $this->xmlWriter->flush(); }
public function writeAttribute($name, $value, $prefix = null, $url = null) { if ($prefix !== null) { $this->cursor->writeAttributeNs($prefix, $name, $url, $value); } else { $this->cursor->writeAttribute($name, $value); } }
public static function output_xml($data, $version = '0.1', $root = 'root', $parameters = array(), $sItemName = 'item') { $xml = new XmlWriter(); $xml->openMemory(); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement($root); $xml->setIndent(true); if (!empty($version)) { $xml->writeAttribute('version', $version); } foreach ($parameters as $paramk => $paramv) { $xml->writeAttribute($paramk, $paramv); } self::writexml($xml, $data, $sItemName); $xml->endElement(); return $xml->outputMemory(true); }
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); }
public function executeXml(AgaviRequestDataHolder $request_data) { $report = $this->prepareReport($request_data); $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement('application'); $xml->writeAttribute('name', $report['application']); $xml->startElement('status'); $xml->text($report['status']); $xml->endElement(); $connections = $report['connections']; $xml->startElement('connections'); foreach ($connections['stats'] as $name => $value) { $xml->writeAttribute($name, $value); } $xml->writeElement('status', $connections['status']); $xml->startElement('stats'); foreach ($connections['stats'] as $name => $value) { $xml->writeElement($name, $value); } $xml->endElement(); // connections/stats foreach ($connections['details'] as $name => $value) { $xml->startElement('connection'); $xml->writeAttribute('name', $name); if (is_array($value)) { $this->array2xml($value, $xml); } else { $xml->writeCData((string) $value); } $xml->endElement(); } $xml->endElement(); // connections $xml->endElement(); // application $xml->endDocument(); return $xml->outputMemory(); }
public function toXml(XmlWriter $x) { $x->startElement('template'); $x->text($this->_template); $x->endElement(); $x->startElement('params'); foreach ($this->getVars() as $k => $v) { $x->startElement('param'); $x->writeAttribute('name', $k); $x->text($v); $x->endElement(); } $x->endElement(); }
function toXml(XmlWriter $x, $writeEnvelope = true) { if ($writeEnvelope) { $x->startElement('http-request'); } $x->startElement('method'); $x->text($this->getMethod()); $x->endElement(); $x->startElement('url'); $x->text($this->getUrl()); $x->endElement(); $x->startElement('headers'); foreach ($this->getHeaders() as $k => $v) { $x->startElement('header'); $x->writeAttribute('name', $k); $x->text($v); $x->endElement(); } $x->endElement(); $x->startElement('params'); foreach ($this->getPostParams() as $k => $v) { $x->startElement('param'); $x->writeAttribute('name', $k); $x->text($v); $x->endElement(); } $x->endElement(); if (!$this->getPostParams() && $this->getBody()) { $x->startElement('body'); $x->writeCdata($this->getBody()); $x->endElement(); } if ($writeEnvelope) { $x->endElement(); } }
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; }
/** * Create document(s) update XML * * @param array $documents * * @return string */ protected function createUpdates(array $documents) { $xml = new \XmlWriter(); $xml->openMemory(); $xml->startElement('add'); foreach ($documents as $document) { $xml->startElement('doc'); foreach ($document as $field) { foreach ((array) $this->fieldValueMapper->map($field) as $value) { $xml->startElement('field'); $xml->writeAttribute('name', $this->nameGenerator->getTypedName($field->name, $field->type)); $xml->text($value); $xml->endElement(); } } $xml->endElement(); } $xml->endElement(); return $xml->outputMemory(true); }
/** * Serialize an object with specified root element name. * * @param object $targetObject The target object. * @param string $rootName The name of the root element. * * @return string */ public static function objectSerialize($targetObject, $rootName) { Validate::notNull($targetObject, 'targetObject'); Validate::isString($rootName, 'rootName'); $xmlWriter = new \XmlWriter(); $xmlWriter->openMemory(); $xmlWriter->setIndent(true); $reflectionClass = new \ReflectionClass($targetObject); $methodArray = $reflectionClass->getMethods(); $attributes = self::_getInstanceAttributes($targetObject, $methodArray); $xmlWriter->startElement($rootName); if (!is_null($attributes)) { foreach (array_keys($attributes) as $attributeKey) { $xmlWriter->writeAttribute($attributeKey, $attributes[$attributeKey]); } } foreach ($methodArray as $method) { if (strpos($method->name, 'get') === 0 && $method->isPublic() && $method->name != 'getAttributes') { $variableName = substr($method->name, 3); $variableValue = $method->invoke($targetObject); if (!empty($variableValue)) { if (gettype($variableValue) === 'object') { $xmlWriter->writeRaw(XmlSerializer::objectSerialize($variableValue, $variableName)); } else { $xmlWriter->writeElement($variableName, $variableValue); } } } } $xmlWriter->endElement(); return $xmlWriter->outputMemory(true); }
function toXml(XmlWriter $x) { $x->startElement('url'); $x->startElement('method'); $x->text($this->getMethod()); $x->endElement(); $x->startElement('scheme'); $x->text($this->getScheme()); $x->endElement(); $x->startElement('base_url'); $x->text($this->getBaseUrl(true)); $x->endElement(); $x->startElement('path_info'); $x->text($this->getPathInfo()); $x->endElement(); $x->startElement('host'); $x->text($this->getHttpHost()); $x->endElement(); $x->startElement('remote_addr'); $x->text($this->getClientIp(false)); $x->endElement(); $x->endElement(); $x->startElement('params'); foreach ($this->getRequestOnlyParams() as $k => $v) { $x->startElement('param'); $x->writeAttribute('name', $k); if (is_array($v) || is_object($v)) { $v = json_encode($v); $x->writeAttribute("serialized", "json"); $x->writeCdata($v); } else { $x->text($v); } $x->endElement(); } $x->endElement(); }
/** * Serializes the atom into XML representation. * * @param array $properties The atom properties. * * @return string */ private function _serializeAtom($properties) { $xmlw = new \XmlWriter(); $xmlw->openMemory(); $xmlw->setIndent(true); $xmlw->startDocument(strtoupper($this->_xmlVersion), $this->_xmlEncoding, 'yes'); $xmlw->startElementNS(null, 'entry', $this->_atomNamespaceName); $xmlw->writeAttribute("xmlns:{$this->_dataServicesPrefix}", $this->_dataServicesNamespaceName); $xmlw->writeAttribute("xmlns:{$this->_dataServicesMetadataPrefix}", $this->_dataServicesMetadataNamespaceName); $xmlw->writeElement('title'); $xmlw->writeElement('updated', Utilities::isoDate()); $xmlw->startElement('author'); $xmlw->writeElement('name'); $xmlw->endElement(); $xmlw->writeElement('id'); $xmlw->startElement('content'); $xmlw->writeAttribute('type', Resources::XML_CONTENT_TYPE); $xmlw->startElementNS($this->_dataServicesMetadataPrefix, 'properties', null); $this->_generateProperties($xmlw, $properties); $xmlw->endElement(); $xmlw->endElement(); $xmlw->endElement(); return $xmlw->outputMemory(true); }
public static function Obj2XML($obj) { $xml = new XmlWriter(); $xml->openMemory(); $xml->setIndent(TRUE); $xml->startElement(get_class($obj)); $xml->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); $xml->writeAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); self::getObject2XML($xml, $obj); $xml->endElement(); $xml->endElement(); return $xml->outputMemory(true); }
/** * Indexes the document $document using definition $definition * * @param ezcSearchDocumentDefinition $definition * @param mixed $document */ public function index(ezcSearchDocumentDefinition $definition, $document) { $xml = new XmlWriter(); $xml->openMemory(); $xml->startElement('add'); $xml->startElement('doc'); $xml->startElement('field'); $xml->writeAttribute('name', 'ezcsearch_type_s'); $xml->text($definition->documentType); $xml->endElement(); $xml->startElement('field'); $xml->writeAttribute('name', 'id'); $xml->text($document[$definition->idProperty]); $xml->endElement(); foreach ($definition->fields as $field) { $value = $this->mapFieldValuesForIndex($field, $document[$field->field]); foreach ($value as $fieldValue) { $xml->startElement('field'); $xml->writeAttribute('name', $this->mapFieldType($field->field, $field->type)); $xml->text($fieldValue); $xml->endElement(); } } $xml->endElement(); $xml->endElement(); $doc = $xml->outputMemory(true); $r = $this->sendRawPostCommand('update', array('wt' => 'json'), $doc); if ($this->inTransaction == 0) { $this->runCommit(); } }
private function writeRootAttributes() { $this->writer->writeAttribute('xmlns:json', 'http://www.ibm.com/xmlns/prod/2009/jsonx'); $this->writer->writeAttribute('xsi:schemaLocation', 'http://www.datapower.com/schemas/json jsonx.xsd'); $this->writer->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); }
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(); }
private function writeCategory(\XmlWriter $writer, Category $category) { $writer->startElement('category'); if ($category->getDomain()) { $writer->writeAttribute('domain', $category->getDomain()); } $writer->writeCdata($category->getTitle()); $writer->endElement(); }
function write(XmlWriter $xml, $data) { $current_element = null; foreach ($data as $key => $value) { $current_element = $key; if (is_array($value)) { foreach ($value as $index => $content) { $xml->startElement($current_element); if (is_array($content)) { // Attributes if (isset($content["@"]) && is_array($content["@"])) { foreach ($content["@"] as $attr => $attr_value) { $xml->writeAttribute($attr, $attr_value); } } // Nested elements if (is_array($content["#"])) { $this->write($xml, $content["#"]); } else { //$xml->writeElement($current_element, $content["#"]); $xml->text($content["#"]); } } $xml->endElement(); //echo $xml->outputMemory(true); } } } }