/** * Create a new PHPPowerPoint_Shared_XMLWriter instance * * @param int $pTemporaryStorage Temporary storage location * @param string $pTemporaryStorageFolder Temporary storage folder */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') { // Create internal XMLWriter $this->_xmlWriter = new XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->_xmlWriter->openMemory(); } else { // Create temporary filename $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml'); // Open storage if ($this->_xmlWriter->openUri($this->_tempFileName) === false) { // Fallback to memory... $this->_xmlWriter->openMemory(); } } // Set default values // proposed to be false in production version $this->_xmlWriter->setIndent(true); //$this->_xmlWriter->setIndent(false); // Set indent // proposed to be '' in production version $this->_xmlWriter->setIndentString(' '); //$this->_xmlWriter->setIndentString(''); }
/** * @param string $path Path to be set * * @return $this */ public function setPath($path) { parent::setPath($path); $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openUri($path); return $this; }
public function __construct($documentUri, $version = '1.0', $encoding = 'utf-8') { $this->xmlWriter = new \XMLWriter(); $this->elementWriter = new ElementWriter($this->xmlWriter); $this->xmlWriter->openUri($documentUri); $this->xmlWriter->setIndent(true); $this->xmlWriter->startDocument($version, $encoding); }
public function initialize(Config $config, $directory, $filenameWithDate = false) { $this->setFilename($config, $directory, $filenameWithDate); $this->xml = new \XMLWriter(); $this->xml->openUri($this->filename); $this->xml->startDocument('1.0', 'utf-8'); $this->xml->setIndent(true); $this->xml->setIndentString(' '); $this->xml->writeComment('list of ' . $config->getClassName()); $this->elementName = strtolower($config->getClassNameLastPart()); $this->xml->startElement(strtolower($config->getClassNameLastPart(true))); }
/** * Create a new \PhpOffice\PhpPowerpoint\Shared\XMLWriter instance * * @param int $pTemporaryStorage Temporary storage location * @param string $pTemporaryStorageDir Temporary storage folder */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = './') { // Create internal XMLWriter $this->xmlWriter = new \XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->xmlWriter->openMemory(); } else { // Create temporary filename $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml'); // Open storage $this->xmlWriter->openUri($this->tempFileName); } // Set default values $this->xmlWriter->setIndent(true); }
/** * Fetches the site with the given name and exports it into XML. * * @param array<\TYPO3\TYPO3\Domain\Model\Site> $sites * @return void */ public function export(array $sites) { $this->nodeRepository->getContext()->setInvisibleContentShown(TRUE); $this->nodeRepository->getContext()->setInaccessibleContentShown(TRUE); $xmlWriter = new \XMLWriter(); $xmlWriter->openUri('php://output'); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('root'); foreach ($sites as $site) { $xmlWriter->startElement('site'); // site attributes $xmlWriter->writeAttribute('nodeName', $site->getNodeName()); // site properties $xmlWriter->startElement('properties'); $xmlWriter->writeElement('name', $site->getName()); $xmlWriter->writeElement('state', $site->getState()); $xmlWriter->writeElement('siteResourcesPackageKey', $site->getSiteResourcesPackageKey()); $xmlWriter->endElement(); // on to the nodes... $node = $this->nodeRepository->getContext()->getNode('/Sites/' . $site->getNodeName()); foreach ($node->getChildNodes() as $childNode) { $this->exportNode($childNode, $xmlWriter); } $xmlWriter->endElement(); } $xmlWriter->endElement(); $xmlWriter->endDocument(); $xmlWriter->flush(); }
/** * @param \XMLWriter $writer * @param resource $stream */ protected function open(\XMLWriter $writer, $stream) { if (is_resource($stream)) { $writer->openMemory(); } else { $writer->openUri($stream); } }
/** * Opens and uri. * * @param string $uri * Uri to be opened. * * @throws XmlSitemapGenerationException * Throws exception when uri cannot be opened. * * @return bool * Returns TRUE when uri was successful opened. */ public function openUri($uri) { $return = parent::openUri($uri); if (!$return) { throw new XmlSitemapGenerationException(t('Could not open file @file for writing.', array('@file' => $uri))); } return $return; }
/** * Create a new PHPExcel_Shared_XMLWriter instance * * @param int $pTemporaryStorage Temporary storage location */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY) { // Create internal XMLWriter $this->_xmlWriter = new XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->_xmlWriter->openMemory(); } else { // Create temporary filename $this->_tempFileName = @tempnam('./', 'xml'); // Open storage if ($this->_xmlWriter->openUri($this->_tempFileName) === false) { // Fallback to memory... $this->_xmlWriter->openMemory(); } } // Set default values $this->_xmlWriter->setIndent(true); }
/** * Fetches the site with the given name and exports it as XML into the given file. * * @param array<Site> $sites * @param boolean $tidy Whether to export formatted XML * @param string $pathAndFilename Path to where the export output should be saved to * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "TYPO3.Neos:Page", "!TYPO3.Neos:Page,TYPO3.Neos:Text") * @return void */ public function exportToFile(array $sites, $tidy = false, $pathAndFilename, $nodeTypeFilter = null) { $this->resourcesPath = Files::concatenatePaths(array(dirname($pathAndFilename), 'Resources')); Files::createDirectoryRecursively($this->resourcesPath); $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openUri($pathAndFilename); $this->xmlWriter->setIndent($tidy); $this->exportSites($sites, $nodeTypeFilter); $this->xmlWriter->flush(); }
/** * */ function __construct($config = array()) { if (!class_exists('XMLWriter')) { require_once 'Spizer/Logger/Exception.php'; throw new Spizer_Logger_Exception('The XMLWriter PHP extension is not loaded'); } $this->_config = array_merge($this->_config, $config); $this->_writer = new XMLWriter(); if (!$this->_writer->openUri($this->_config['target'])) { require_once 'Spizer/Logger/Exception.php'; throw new Spizer_Logger_Exception('Cannot open log file "' . $this->_config['target'] . '" for writing'); } $this->_writer->setIndent($this->_config['indent']); $this->_writer->setIndentString($this->_config['indentstr']); $this->_writer->startDocument('1.0', 'UTF-8'); $this->_writer->startElement('spizerlog'); $this->_writer->writeAttribute('xmlns', 'http://arr.gr/spizer/xmllog/1.0'); $this->_writer->writeAttribute('microtime', microtime(true)); }
/** * Create a new \PhpOffice\PhpPowerpoint\Shared\XMLWriter instance * * @param int $pTemporaryStorage Temporary storage location * @param string $pTemporaryStorageDir Temporary storage folder */ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = './', $compatibility = false) { // Create internal XMLWriter $this->xmlWriter = new \XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { $this->xmlWriter->openMemory(); } else { // Create temporary filename $this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml'); // Open storage $this->xmlWriter->openUri($this->tempFileName); } if ($compatibility) { $this->xmlWriter->setIndent(false); $this->xmlWriter->setIndentString(''); } else { $this->xmlWriter->setIndent(true); $this->xmlWriter->setIndentString(' '); } }
/** * Writes the schema difference definition in $dbSchema to the file $file. * * @param string $file * @param ezcDbSchemaDiff $dbSchema * @todo throw exception when file can not be opened */ public function saveDiffToFile($file, ezcDbSchemaDiff $dbSchema) { $this->writer = new XMLWriter(); if (!@$this->writer->openUri($file)) { throw new ezcBaseFilePermissionException($file, ezcBaseFileException::WRITE); } $this->writer->startDocument('1.0', 'utf-8'); $this->writer->setIndent(true); $this->writer->startElement('database'); $this->writer->flush(); // New tables $this->writer->startElement('new-tables'); $this->writer->flush(); foreach ($dbSchema->newTables as $tableName => $table) { $this->writeTable($tableName, $table); $this->writer->flush(); } $this->writer->endElement(); $this->writer->flush(); // Removed tables $this->writer->startElement('removed-tables'); $this->writer->flush(); foreach ($dbSchema->removedTables as $tableName => $tableStatus) { $this->writer->startElement('table'); $this->writer->startElement('name'); $this->writer->text($tableName); $this->writer->endElement(); $this->writer->startElement('removed'); $this->writer->text($tableStatus ? 'true' : 'false'); $this->writer->endElement(); $this->writer->endElement(); $this->writer->flush(); } $this->writer->endElement(); $this->writer->flush(); // Changed tables $this->writer->startElement('changed-tables'); $this->writer->flush(); foreach ($dbSchema->changedTables as $tableName => $table) { $this->writeChangedTable($tableName, $table); $this->writer->flush(); } $this->writer->endElement(); $this->writer->flush(); $this->writer->endElement(); $this->writer->endDocument(); }
function dump_xml_file($lang, $outDir, $grammemsPrefix, $posesPrefix) { $lang = strtolower($lang); $out_file = "{$outDir}/{$lang}.xml"; $clazz = 'ConstNames_' . ucfirst($lang); $php_file = dirname(__FILE__) . '/' . $lang . '.php'; require_once $php_file; $obj = new $clazz(); $writer = new XMLWriter(); $writer->openUri($out_file); $writer->setIndent(true); $writer->setIndentString(" "); $writer->startDocument('1.0', 'UTF-8'); $writer->startElement('gramtab'); // parts of speech $writer->startElement('part_of_speech'); foreach ($obj->getPartsOfSpeech() as $pos) { $writer->startElement('pos'); $writer->writeAttribute('name', $pos['short_name']); $writer->writeAttribute('const_name', $posesPrefix . $pos['long_name']); $writer->writeAttribute('id', $pos['id']); $writer->endElement(); } $writer->endElement(); // grammems $writer->startElement('grammems'); $shift = 0; foreach ($obj->getGrammems() as $grammem) { $writer->startElement('grammem'); $writer->writeAttribute('name', $grammem['short_name']); $writer->writeAttribute('const_name', $grammemsPrefix . $grammem['long_name']); $writer->writeAttribute('id', $grammem['id']); $writer->writeAttribute('shift', $shift); $shift++; $writer->endElement(); } $writer->endElement(); $writer->endElement(); $writer->endDocument(); }
function create_item($arr) { // 属性数组 $attribute_array = array('title' => array('size' => 1)); $xml = new XMLWriter(); $xml->openUri("php://output"); // 输出方式,也可以设置为某个xml文件地址,直接输出成文件 $xml->setIndentString(' '); $xml->setIndent(true); $xml->startDocument('1.0', 'utf-8'); // 开始创建文件 // 根结点 $xml->startElement('article'); foreach ($arr as $data) { $xml->startElement('item'); if (is_array($data)) { foreach ($data as $key => $row) { $xml->startElement($key); if (isset($attribute_array[$key]) && is_array($attribute_array[$key])) { foreach ($attribute_array[$key] as $akey => $aval) { // 设置属性值 $xml->writeAttribute($akey, $aval); } } $xml->text($row); // 设置内容 $xml->endElement(); // $key } } $xml->endElement(); // item } $xml->endElement(); // article $xml->endDocument(); $xml->flush(); }
<?php /* $Id$ */ $doc_dest = '001.xml'; $xw = new XMLWriter(); $xw->openUri($doc_dest); $xw->startDocument('1.0', 'UTF-8', 'standalonearg'); $xw->startElement("tag1"); $xw->endDocument(); // Force to write and empty the buffer $output_bytes = $xw->flush(true); echo file_get_contents($doc_dest); unset($xw); unlink('001.xml'); ?> ===DONE===
<?php // CLI script to identify missing SCORM content files and // write the details to XML define('CLI_SCRIPT', 1); // Run from /admin/cli dir require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; // Where are the SCORM .zip files? $scormfolder = '/'; // Include trailing slash // Create arrays to record SCORM file details $found = array(); $notfound = array(); $writer = new XMLWriter(); $writer->openUri('missing_scorm_content.xml'); $writer->startDocument(); $writer->setIndent(4); $writer->startElement('resultset'); $scormcontent = simplexml_load_file('scorm_content.xml') or die('wtf'); foreach ($scormcontent->children() as $scormdetails) { $courseid = (int) $scormdetails->field['0']; $cmid = (int) $scormdetails->field['1']; $scormid = (int) $scormdetails->field['2']; $coursename = (string) $scormdetails->field['3']; $scormname = (string) $scormdetails->field['4']; $filename = (string) $scormdetails->field['5']; if (!file_exists($scormfolder . $filename)) { $notfound[] = $filename; $writer->startElement('row'); // course_id $writer->startElement('field');
/** * @see interface_admin_systemtask::executeTask() * @throws class_exception * @return string */ public function executeTask() { if (!class_module_system_module::getModuleByName("pages")->rightEdit()) { return $this->getLang("commons_error_permissions"); } //load the page itself $objPage = class_module_pages_page::getPageByName($this->getParam("pageExport")); if ($objPage !== null) { $objSystem = class_module_system_module::getModuleByName("system"); $objXmlWriter = new XMLWriter(); $strExportFolder = $this->getParam("exportFolder"); $strExportPrefix = $this->getParam("exportPrefix"); if ($strExportFolder == "") { $strExportFolder = _realpath_ . _projectpath_ . "/temp"; } else { $strExportFolder = _realpath_ . "/" . $strExportFolder; } if ($strExportPrefix != "") { $strExportPrefix = "_" . $strExportPrefix; } if (is_dir($strExportFolder)) { if (!$objXmlWriter->openUri($strExportFolder . "/" . $strExportPrefix . $objPage->getSystemid() . ".xml")) { throw new class_exception("failed to open export file ", class_exception::$level_ERROR); } //$objXmlWriter->openMemory(); $objXmlWriter->setIndent(true); $objXmlWriter->startDocument("1.0", "UTF-8"); $objXmlWriter->startComment(); $strComment = "\n Kajona XML export\n"; $strComment .= " (c) Kajona, www.kajona.de\n"; $strComment .= " Kernel version: " . $objSystem->getStrVersion() . "\n"; $strComment .= " Schema version: 1.0\n"; $strComment .= " Export Date: " . dateToString(new class_date()) . "\n"; $objXmlWriter->text($strComment); $objXmlWriter->endComment(); $objXmlWriter->startElement("pages"); $objXmlWriter->startElement("page"); $objXmlWriter->startElement("metadata"); $objXmlWriter->startElement("kernelVersion"); $objXmlWriter->text($objSystem->getStrVersion()); $objXmlWriter->endElement(); $objXmlWriter->startElement("systemid"); $objXmlWriter->text($objPage->getSystemid()); $objXmlWriter->endElement(); $objXmlWriter->startElement("previd"); $objXmlWriter->text($objPage->getPrevId()); $objXmlWriter->endElement(); $objXmlWriter->startElement("pagename"); $objXmlWriter->text($objPage->getStrName()); $objXmlWriter->endElement(); //try to load the parent page-name $strParentName = ""; if (validateSystemid($objPage->getPrevId())) { $objParentPage = new class_module_pages_page($objPage->getPrevId()); $strParentName = $objParentPage->getStrName(); } $objXmlWriter->startElement("prevname"); $objXmlWriter->text($strParentName); $objXmlWriter->endElement(); $objXmlWriter->startElement("pageproperties"); $this->createPageMetadata($objPage->getSystemid(), $objXmlWriter); $objXmlWriter->endElement(); //metadata $objXmlWriter->endElement(); $objXmlWriter->startElement("elements"); $this->createElementData($objPage->getSystemid(), $objXmlWriter); $objXmlWriter->endElement(); //page $objXmlWriter->endElement(); //pages $objXmlWriter->endElement(); $objXmlWriter->flush(); //return $objXmlWriter->outputMemory(true); return $this->getLang("systemtask_pageexport_success") . $strExportFolder . "/" . $strExportPrefix . $objPage->getSystemid() . ".xml" . ""; } else { throw new class_exception("writing XML: Folder " . $strExportFolder . " does not exist! ", class_exception::$level_ERROR); } } return $this->getLang("systemtask_pageexport_error"); }
/* * This file is part of the XMLReaderIterator package. * * Copyright (C) 2012, 2014 hakre <http://hakre.wordpress.com> * * Example: Write XML with XMLWriter while reading from XMLReader with XMLWriterIteration */ require 'xmlreader-iterators.php'; // require XMLReaderIterator library $xmlInputFile = 'data/dobs-items.xml'; $xmlOutputFile = 'php://output'; $reader = new XMLReader(); $reader->open($xmlInputFile); $writer = new XMLWriter(); $writer->openUri($xmlOutputFile); $iterator = new XMLWritingIteration($writer, $reader); $writer->startDocument(); $itemsCount = 0; $itemCount = 0; foreach ($iterator as $node) { $isElement = $node->nodeType === XMLReader::ELEMENT; if ($isElement && $node->name === 'ITEMS') { // increase counter for <ITEMS> elements and reset <ITEM> counter $itemsCount++; $itemCount = 0; } if ($isElement && $node->name === 'ITEM') { // increase <ITEM> counter and insert "id" attribute $itemCount++; $writer->startElement($node->name);
private function createXmlWriter($fileName) { $writer = new XMLWriter(); if (false === $writer->openUri($fileName)) { throw new Exception("Can`t create {$fileName} xml file for XMLWriter"); } $writer->setIndentString("\t"); $writer->setIndent(4); return $writer; }
function generate_nuds($row) { global $stylesheet; global $deities; $recordId = 'price.' . $row['Price no.']; if ($row['Material'] != 'vacat') { $doc = new XMLWriter(); //$doc->openUri('php://output'); $doc->openUri('nuds/' . $recordId . '.xml'); $doc->setIndent(true); //now we need to define our Indent string,which is basically how many blank spaces we want to have for the indent $doc->setIndentString(" "); $doc->startDocument('1.0', 'UTF-8'); $doc->startElement('nuds'); $doc->writeAttribute('xmlns', 'http://nomisma.org/nuds'); $doc->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema'); $doc->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $doc->writeAttribute('recordType', 'conceptual'); //control $doc->startElement('control'); $doc->writeElement('recordId', $recordId); $doc->writeElement('publicationStatus', 'approved'); $doc->startElement('maintenanceAgency'); $doc->writeElement('agencyName', 'American Numismatic Society'); $doc->endElement(); $doc->writeElement('maintenanceStatus', 'derived'); //maintenanceHistory $doc->startElement('maintenanceHistory'); $doc->startElement('maintenanceEvent'); $doc->writeElement('eventType', 'derived'); $doc->startElement('eventDateTime'); $doc->writeAttribute('standardDateTime', date(DATE_W3C)); $doc->text(date(DATE_RFC2822)); $doc->endElement(); $doc->writeElement('agentType', 'machine'); $doc->writeElement('agent', 'PHP'); $doc->writeElement('eventDescription', 'Generated from CSV fro Google Drive.'); $doc->endElement(); $doc->endElement(); //semanticDeclaration $doc->startElement('semanticDeclaration'); $doc->writeElement('prefix', 'dcterms'); $doc->writeElement('namespace', 'http://purl.org/dc/terms/'); $doc->endElement(); $doc->startElement('semanticDeclaration'); $doc->writeElement('prefix', 'nmo'); $doc->writeElement('namespace', 'http://nomisma.org/ontology#'); $doc->endElement(); //rightsStmt $doc->startElement('rightsStmt'); $doc->writeElement('copyrightHolder', 'American Numismatic Society'); $doc->startElement('license'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:href', 'http://opendatacommons.org/licenses/odbl/'); $doc->endElement(); $doc->endElement(); $doc->endElement(); //descMeta $doc->startElement('descMeta'); //generate title $title = "Price {$row['Price no.']}"; $doc->startElement('title'); $doc->writeAttribute('xml:lang', 'en'); $doc->text($title); $doc->endElement(); /***** TYPEDESC *****/ $doc->startElement('typeDesc'); //objectType $doc->startElement('objectType'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/coin'); $doc->text('Coin'); $doc->endElement(); //manufacture $doc->startElement('manufacture'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/struck'); $doc->text('Struck'); $doc->endElement(); if (strlen($row['Material']) > 0) { $vals = explode('|', $row['Material']); foreach ($vals as $val) { if (substr($val, -1) == '?') { $uri = 'http://nomisma.org/id/' . substr($val, 0, -1); $uncertainty = true; $content = processUri($uri); } else { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = false; $content = processUri($uri); } $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:href', $uri); $doc->text($content['label']); $doc->endElement(); } } if (strlen($row['Denomination']) > 0) { $vals = explode('|', $row['Denomination']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = false; $content = processUri($uri); $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:href', $uri); $doc->text($content['label']); $doc->endElement(); } } if (is_numeric($row['From Date']) && is_numeric($row['To Date'])) { if ($row['From Date'] == $row['To Date']) { $doc->startElement('date'); $doc->writeAttribute('standardDate', number_pad($row['From Date'], 4)); $doc->text(abs(intval($row['From Date'])) . ' B.C.'); $doc->endElement(); } else { $doc->startElement('dateRange'); $doc->startElement('fromDate'); $doc->writeAttribute('standardDate', number_pad($row['From Date'], 4)); $doc->text(abs(intval($row['From Date'])) . ' B.C.'); $doc->endElement(); $doc->startElement('toDate'); $doc->writeAttribute('standardDate', number_pad($row['To Date'], 4)); $doc->text(abs(intval($row['To Date'])) . ' B.C.'); $doc->endElement(); $doc->endElement(); } } //authority if (strlen($row['Authority']) > 0 || strlen($row['Stated authority']) > 0 || strlen($row['Magistrate ID 1']) > 0 || strlen($row['Magistrate ID 2']) > 0) { $doc->startElement('authority'); if (strlen($row['Authority']) > 0) { $vals = explode('|', $row['Authority']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = false; $content = processUri($uri); $role = 'authority'; $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', $role); $doc->writeAttribute('xlink:href', $uri); if ($uncertainty == true) { $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } } /*elseif (strlen($row['Mint ID']) > 0 && $row['Mint ID'] != 'uncertain_value'){ $vals = explode('|', $row['Mint ID']); foreach ($vals as $val){ $uri = 'http://nomisma.org/id/' . $val; $uncertainty = (strtolower(trim($row['Mint Uncertain'])) == 'true' ? true : false); $content = processUri($uri); $doc->startElement('corpname'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'authority'); $doc->writeAttribute('xlink:href', $uri); if($uncertainty == true){ $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } }*/ if (strlen($row['Stated authority']) > 0) { $vals = explode('|', $row['Stated authority']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = false; $content = processUri($uri); $role = 'statedAuthority'; $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', $role); $doc->writeAttribute('xlink:href', $uri); if ($uncertainty == true) { $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } } //magistrates if (strlen($row['Magistrate ID 1']) > 0) { $vals = explode('|', $row['Magistrate ID 1']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = false; $content = processUri($uri); $role = 'issuer'; $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', $role); $doc->writeAttribute('xlink:href', $uri); if ($uncertainty == true) { $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } } if (strlen($row['Magistrate ID 2']) > 0) { $vals = explode('|', $row['Magistrate ID 2']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = false; $content = processUri($uri); $role = 'issuer'; $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', $role); $doc->writeAttribute('xlink:href', $uri); if ($uncertainty == true) { $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } } $doc->endElement(); } //geography //mint if (strlen($row['Mint ID']) > 0 || strlen($row['Region']) > 0) { $doc->startElement('geographic'); if (strlen($row['Mint ID']) > 0) { $vals = explode('|', $row['Mint ID']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = strtolower(trim($row['Mint Uncertain'])) == 'true' ? true : false; $content = processUri($uri); $doc->startElement('geogname'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'mint'); $doc->writeAttribute('xlink:href', $uri); if ($uncertainty == true) { $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } //regions extracted at the point of indexing in Numishare /*if (isset($content['parent'])){ $orgs[] = $content['parent']; $parentArray = processUri($content['parent']); $role = 'region'; $doc->startElement($parentArray['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', $role); $doc->writeAttribute('xlink:href', $content['parent']); $doc->text($parentArray['label']); $doc->endElement(); }*/ } if (strlen($row['Region']) > 0) { $vals = explode('|', $row['Region']); foreach ($vals as $val) { $uri = 'http://nomisma.org/id/' . $val; $uncertainty = strtolower(trim($row['Region Uncertain'])) == 'true' ? true : false; $content = processUri($uri); $doc->startElement($content['element']); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'region'); $doc->writeAttribute('xlink:href', $uri); if ($uncertainty == true) { $doc->writeAttribute('certainty', 'uncertain'); } $doc->text($content['label']); $doc->endElement(); } } $doc->endElement(); } //obverse if (strlen($row['O']) > 0) { $doc->startElement('obverse'); $key = trim($row['O']); $type = ''; $doc->startElement('type'); foreach ($stylesheet as $desc) { if ($desc['Abbreviation'] == $key) { $type = $desc['en']; foreach ($desc as $k => $v) { if ($k != 'Abbreviation') { $doc->startElement('description'); $doc->writeAttribute('xml:lang', $k); $doc->text(trim($v)); $doc->endElement(); } } break; } } $doc->endElement(); //deity foreach ($deities as $deity) { if (strstr($deity['name'], ' ') !== FALSE) { //haystack is string when the deity is multiple words $haystack = strtolower(trim($type)); if (strstr($haystack, strtolower($deity['matches'])) !== FALSE) { $bm_uri = strlen($deity['bm_uri']) > 0 ? ' xlink:href="' . $deity['bm_uri'] . '"' : ''; $doc->startElement('persname'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'deity'); if (strlen($deity['bm_uri']) > 0) { $doc->writeAttribute('xlink:href', $deity['bm_uri']); } $doc->text($deity['name']); $doc->endElement(); } } else { //haystack is array $string = preg_replace('/[^a-z]+/i', ' ', trim($type)); $haystack = explode(' ', $string); if (in_array($deity['matches'], $haystack)) { $doc->startElement('persname'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'deity'); if (strlen($deity['bm_uri']) > 0) { $doc->writeAttribute('xlink:href', $deity['bm_uri']); } $doc->text($deity['name']); $doc->endElement(); } } } //symbols if (strlen($row['Ο: to l.']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftField'); $doc->text(trim($row['Ο: to l.'])); $doc->endElement(); } if (strlen($row['O: to r.']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'rightField'); $doc->text(trim($row['O: to r.'])); $doc->endElement(); } if (strlen($row['O:below']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'below'); $doc->text(trim($row['O:below'])); $doc->endElement(); } if (strlen($row['O:Scalp']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'scalp'); $doc->text(trim($row['O:Scalp'])); $doc->endElement(); } $doc->endElement(); } //reverse if (strlen($row['R']) > 0 || strlen($row['R Legend']) > 0) { $doc->startElement('reverse'); $key = trim($row['R']); $type = ''; $doc->startElement('type'); foreach ($stylesheet as $desc) { if ($desc['Abbreviation'] == $key) { $type = $desc['en']; foreach ($desc as $k => $v) { if ($k != 'Abbreviation') { $doc->startElement('description'); $doc->writeAttribute('xml:lang', $k); $doc->text(trim($v)); $doc->endElement(); } } break; } } $doc->endElement(); //deity foreach ($deities as $deity) { if (strstr($deity['name'], ' ') !== FALSE) { //haystack is string when the deity is multiple words $haystack = strtolower(trim($type)); if (strstr($haystack, strtolower($deity['matches'])) !== FALSE) { $bm_uri = strlen($deity['bm_uri']) > 0 ? ' xlink:href="' . $deity['bm_uri'] . '"' : ''; $doc->startElement('persname'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'deity'); if (strlen($deity['bm_uri']) > 0) { $doc->writeAttribute('xlink:href', $deity['bm_uri']); } $doc->text($deity['name']); $doc->endElement(); } } else { //haystack is array $string = preg_replace('/[^a-z]+/i', ' ', trim($type)); $haystack = explode(' ', $string); if (in_array($deity['matches'], $haystack)) { $doc->startElement('persname'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:role', 'deity'); if (strlen($deity['bm_uri']) > 0) { $doc->writeAttribute('xlink:href', $deity['bm_uri']); } $doc->text($deity['name']); $doc->endElement(); } } } //legend if (strlen($row['R Legend']) > 0) { $doc->startElement('legend'); $doc->writeAttribute('scriptCode', 'Grek'); $doc->text(trim($row['R Legend'])); $doc->endElement(); } //symbols if (strlen($row['<LF>1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftField'); $doc->text(trim($row['<LF>1'])); $doc->endElement(); } if (strlen($row['<LF>2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftField'); $doc->text(trim($row['<LF>2'])); $doc->endElement(); } if (strlen($row['<LF>3']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftField'); $doc->text(trim($row['<LF>3'])); $doc->endElement(); } if (strlen($row['<LF>4']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftField'); $doc->text(trim($row['<LF>4'])); $doc->endElement(); } if (strlen($row['<TH>1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'beneathThrone'); $doc->text(trim($row['<TH>1'])); $doc->endElement(); } if (strlen($row['<TH>2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'beneathThrone'); $doc->text(trim($row['<TH>2'])); $doc->endElement(); } if (strlen($row['<TH>3']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'beneathThrone'); $doc->text(trim($row['<TH>3'])); $doc->endElement(); } if (strlen($row['<EX>1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'exergue'); $doc->text(trim($row['<EX>1'])); $doc->endElement(); } if (strlen($row['<EX>2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'exergue'); $doc->text(trim($row['<EX>2'])); $doc->endElement(); } if (strlen($row['<EX>3']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'exergue'); $doc->text(trim($row['<EX>3'])); $doc->endElement(); } if (strlen($row['<RF>1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'rightField'); $doc->text(trim($row['<RF>1'])); $doc->endElement(); } if (strlen($row['<RF>2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'rightField'); $doc->text(trim($row['<RF>2'])); $doc->endElement(); } if (strlen($row['Above1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'above'); $doc->text(trim($row['Above1'])); $doc->endElement(); } if (strlen($row['Above2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'above'); $doc->text(trim($row['Above2'])); $doc->endElement(); } if (strlen($row['Below1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'below'); $doc->text(trim($row['Below1'])); $doc->endElement(); } if (strlen($row['Below2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'below'); $doc->text(trim($row['Below2'])); $doc->endElement(); } if (strlen($row['<LW>1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftWing'); $doc->text(trim($row['<LW>1'])); $doc->endElement(); } if (strlen($row['<LW>2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'leftWing'); $doc->text(trim($row['<LW>2'])); $doc->endElement(); } if (strlen($row['<RW>1']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'rightWing'); $doc->text(trim($row['<RW>1'])); $doc->endElement(); } if (strlen($row['<RW>2']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'rightWing'); $doc->text(trim($row['<RW>2'])); $doc->endElement(); } if (strlen($row['Between']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'between'); $doc->text(trim($row['Between'])); $doc->endElement(); } if (strlen($row['Boss']) > 0) { $doc->startElement('symbol'); $doc->writeAttribute('position', 'boss'); $doc->text(trim($row['Boss'])); $doc->endElement(); } $doc->endElement(); } //end typeDesc $doc->endElement(); //refDesc $doc->startElement('refDesc'); $doc->startElement('reference'); $doc->writeAttribute('xlink:type', 'simple'); $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/price1991'); $doc->writeAttribute('semantic', 'dcterms:source'); $doc->text('Price (1991)'); $doc->endElement(); $doc->endElement(); //end descMeta $doc->endElement(); //end nuds $doc->endElement(); $doc->endDocument(); echo "Writing {$recordId}\n"; } else { "Ignoring vacat: {$recordId}\n"; } }
<?php /** * @link https://github.com/corpsepk/yii2-yandex-market-yml * @copyright Copyright (c) 2016 Corpsepk * @license http://opensource.org/licenses/MIT * * @var $shop corpsepk\yml\models\Shop */ use yii\helpers\Html; $writer = new XMLWriter(); $writer->openUri('php://output'); $writer->startDocument('1.0', 'UTF-8'); $writer->startDtd('yml_catalog SYSTEM "shops.dtd"'); $writer->endDtd(); $writer->startElement('yml_catalog'); $writer->writeAttribute('date', date('Y-m-d H:i')); $writer->startElement('shop'); $writer->writeElement('name', Html::encode($shop->name)); $writer->writeElement('company', Html::encode($shop->company)); $writer->writeElement('url', Html::encode($shop->url)); foreach ($shop->optionalAttributes as $attribute) { if (empty($shop->{$attribute})) { continue; } if (is_array($shop->{$attribute})) { foreach ($shop->{$attribute} as $value) { $writer->writeElement($attribute, Html::encode($value)); } } else { $writer->writeElement($attribute, Html::encode($shop->{$attribute}));
<?php $xw = new XMLWriter(); $xw->openUri('test.xml'); $xw->startDocument("1.0"); $xw->startElement("book"); $xw->text("example"); $xw->endElement(); $xw->endDocument(); $xw->flush(0);
/** * Init writter * * @param string $filename */ private function initWriter($filename) { $this->xml = new \XMLWriter(); $this->xml->openUri($filename); $this->xml->setIndent(true); }
function renderTestCoverage(Aggregator $agg, $test) { $reltest = str_replace($agg->testpath . '/', '', $test); $output = new \XMLWriter(); if (!$output->openUri('php://output')) { throw new Exception('Cannot render test ' . $reltest . ' coverage, opening XML failed'); } $output->setIndentString(' '); $output->setIndent(true); $output->startElement('html'); $output->startElement('head'); $output->writeElement('title', 'Code Coverage Summary for test ' . $reltest); $output->startElement('link'); $output->writeAttribute('href', 'cover.css'); $output->writeAttribute('rel', 'stylesheet'); $output->writeAttribute('type', 'text/css'); $output->endElement(); $output->endElement(); $output->startElement('body'); $this->logoutLink($output); $output->writeElement('h2', 'Code Coverage Files for test ' . $reltest); $output->startElement('ul'); $paths = $agg->retrievePathsForTest($test); foreach ($paths as $name) { $source = new SourceFile\PerTest($name, $agg, $agg->testpath, $agg->codepath, $test); $output->startElement('li'); $percent = $source->coveragePercentage(); $output->startElement('div'); if ($percent < 50) { $output->writeAttribute('class', 'bad'); } elseif ($percent < 75) { $output->writeAttribute('class', 'ok'); } else { $output->writeAttribute('class', 'good'); } $output->text(' Coverage: ' . str_pad($source->coveragePercentage() . '%', 4, ' ', STR_PAD_LEFT)); $output->endElement(); $output->startElement('a'); $output->writeAttribute('href', $this->mangleFile($name, $test)); $output->text($source->shortName()); $output->endElement(); $output->endElement(); } $output->endElement(); $output->endElement(); $output->endDocument(); }
<?php if (!isset($_SERVER['argv'][1])) { die("You must specify an input file!\n"); } $inFile = $_SERVER['argv'][1]; $writer = new XMLWriter(); $writer->openUri('php://stdout'); $writer->setIndent(true); $writer->setIndentString(" "); $converter = new HumanHelp_Xml_Converter_RobohelpXhtml($inFile); $converter->setWriter($writer); $converter->convert(); class HumanHelp_Xml_Converter_RobohelpXhtml { /** * Reader object used to parse the RoboHelp XML file * * @var XMLReader */ protected $_reader = null; /** * Writer object used to write the HumanHelp TOC file * * @var XMLWriter */ protected $_writer = null; public function __construct($inFile) { $this->_reader = new XMLReader(); $this->_reader->open($inFile);
function renderTestCoverage(Aggregator $agg, $testpath, $basePath) { $this->renderTestSummary($agg, $testpath); $testpaths = $agg->retrieveTestPaths(); echo "Rendering test files\n"; foreach ($testpaths as $i => $test) { echo '(', $i + 1, ' of ', count($testpaths) . ') ', $test; $reltest = str_replace($testpath . '/', '', $test); $output = new \XMLWriter(); if (!$output->openUri($this->mangleTestPath($test))) { throw new Exception('Cannot render test ' . $reltest . ' coverage, opening XML failed'); } $output->setIndentString(' '); $output->setIndent(true); $output->startElement('html'); $output->startElement('head'); $output->writeElement('title', 'Code Coverage Summary for test ' . $reltest); $output->startElement('link'); $output->writeAttribute('href', 'cover.css'); $output->writeAttribute('rel', 'stylesheet'); $output->writeAttribute('type', 'text/css'); $output->endElement(); $output->endElement(); $output->startElement('body'); $output->writeElement('h2', 'Code Coverage Files for test ' . $reltest); $output->startElement('ul'); $paths = $agg->retrievePathsForTest($test); foreach ($paths as $name) { echo '.'; $source = new SourceFile\PerTest($name, $agg, $testpath, $basePath, $test); $this->render($source, $reltest); $output->startElement('li'); $percent = $source->coveragePercentage(); $output->startElement('span'); if ($percent < 50) { $output->writeAttribute('class', 'bad'); } elseif ($percent < 75) { $output->writeAttribute('class', 'ok'); } else { $output->writeAttribute('class', 'good'); } $output->text(' Coverage: ' . str_pad($source->coveragePercentage() . '%', 4, ' ', STR_PAD_LEFT)); $output->endElement(); $output->startElement('a'); $output->writeAttribute('href', $this->mangleFile($name, $reltest)); $output->text($source->shortName()); $output->endElement(); $output->endElement(); } echo "done\n"; $output->endElement(); $output->endElement(); $output->endDocument(); } echo "done\n"; }
/** * Create repository of documents according to the type of the folder. * * @link http://www.openarchives.org/OAI/2.0/guidelines-static-repository.htm * * @internal The prefix oai is needed anywhere, because the namespace of the * static repository is not the same than the main oai openarchives. */ protected function _createStaticRepository() { // Create the xml for the static repository. $writer =& $this->_writer; $documentWriter =& $this->_documentWriter; $this->_createTempXmlFile(); // Set the xml. Xml Writer is used because the repository can be big. $writer = new XMLWriter(); $writer->openUri($this->_xmlpathTemp); $writer->setIndent(self::XML_INDENT); $writer->setIndentString(' '); $writer->startDocument('1.0', 'UTF-8'); // Prepare the static repository. $this->_startStaticRepository(); $this->_identifyRepository(); // List the metadata formats of the repository. $writer->startElement('ListMetadataFormats'); foreach ($this->_metadataFormats as $prefix => $format) { $writer->startElement('oai:metadataFormat'); $format->setWriter($writer); $format->fillMetadataFormat(); $writer->endElement(); } $writer->endElement(); // Metadata may be different when files are separated. $recordsForFiles = (bool) $this->_getParameter('records_for_files'); if ($this->_folder->hasBeenStopped()) { return; } // Prepare the document writer, that will be emptied for each document. $documentWriter = new XMLWriter(); $documentWriter->openMemory(); $documentWriter->setIndent(self::XML_INDENT); $documentWriter->setIndentString(' '); // The document has no xml header. // Prepare the writer for each format. foreach ($this->_metadataFormats as $prefix => $format) { $format->setWriter($documentWriter); } // For all formats, loop all documents to create the xml records. foreach ($this->_metadataFormats as $prefix => $format) { $writer->startElement('ListRecords'); $writer->writeAttribute('metadataPrefix', $format->getMetadataPrefix()); foreach ($this->_documents as $indexDocument => $document) { $this->_fillRecord($document, $prefix, 'Item', $indexDocument); if ($recordsForFiles && isset($document['files']) && $format->getParameterFormat('support_separated_files')) { foreach ($document['files'] as $order => $file) { $this->_fillRecord($file, $prefix, 'File', $order); } } $documentWriter->flush(); $writer->flush(); if ($this->_folder->hasBeenStopped()) { return; } } // End ListRecords. $writer->endElement(); } // End the static repository. $writer->endDocument(); $writer->flush(); }
public function write2xmlOp($path) { $xml = new XMLWriter(); $uri = $path . 'test.xml'; $xml->openUri($path); // 输出方式,也可以设置为某个xml文件地址,直接输出成文件 $xml->setIndentString(' '); $xml->setIndent(true); $xml->startDocument('1.0'); // 开始创建文件 // 根结点 $xml->startElement('krpano'); $xml->writeAttribute('onstart', 'startup();'); $xml->writeAttribute('version', '1.16'); $xml->writeAttribute('title', ''); $xml->startElement('include'); $xml->writeAttribute('url', 'skin/vtourskin.xml'); //皮肤路径 $xml->endElement(); $xml->startElement('skin_settings'); $xml->writeAttribute('controlbar_offset', '20'); $xml->writeAttribute('tooltips_mapspots', 'true'); $xml->writeAttribute('tooltips_hotspots', 'true'); $xml->writeAttribute('tooltips_thumbs', 'true'); $xml->writeAttribute('thumbs_scrollindicator', 'false'); $xml->writeAttribute('thumbs_scrollbuttons', 'false'); $xml->writeAttribute('thumbs_onhoverscrolling', 'false'); $xml->writeAttribute('thumbs_draggin', 'true'); $xml->writeAttribute('thumbs_text', 'true'); $xml->writeAttribute('thumbs_opened', 'true'); $xml->writeAttribute('thumbs_crop', '0|40|240|160'); $xml->writeAttribute('thumbs_padding', '10'); $xml->writeAttribute('thumbs_height', '80'); $xml->writeAttribute('thumbs_width', '120'); $xml->writeAttribute('gyro', 'true'); $xml->writeAttribute('bingmaps_zoombuttons', 'false'); $xml->writeAttribute('bingmaps_key', ''); $xml->writeAttribute('bingmaps', 'false'); $xml->endElement(); $xml->startElement('layer'); $xml->writeAttribute('url', ''); $xml->writeAttribute('opened_onclick', 'openurl(\'...\',_blank);'); $xml->writeAttribute('scale', '0.25'); $xml->writeAttribute('name', 'skin_logo'); $xml->endElement(); $xml->startElement('action'); $xml->writeAttribute('namae', 'startup'); $xml->text('if(startscene === null, copy(startscene,scene[0].name)); loadscene(get(startscene), null, MERGE);'); $xml->endElement(); write_sence($xml); $xml->endElement(); // article $xml->endDocument(); $xml->flush(); }
<?php include 'api.php'; // Capture the arguments $classname = str_replace("::", "\\", $argv[1]); $infile = $argv[2]; $outfile = $argv[3]; // Deserialize to an object $xml = new XMLReader(); if (!$xml->open($infile)) { throw new \Exception('Unable to open ' . $infile . '/sample-gx.xml'); } eval("\$o = new {$classname}(\$xml);"); $writer = new \XMLWriter(); $writer->openUri($outfile); $writer->startDocument(); $writer->setIndent(4); $o->toXml($writer); $writer->flush();