note 104240 added to ref.xmlwriter

From: Date: Fri, 03 Jun 2011 01:43:02 +0000
Subject: note 104240 added to ref.xmlwriter
Groups: php.notes 
Request: Send a blank email to php-notes+get-180211@lists.php.net to get a copy of this message
Inspired in the XmlConstruct. <?php class XLIFFConstruct extends XMLWriter { /** * Constructor. * @param string $prm_rootElementName A root element's name of a current xml document * @param string $prm_xsltFilePath Path of a XSLT file. * @access public * @param null */ var $_phrase_id=1; public function __construct(){ $this->openMemory(); $this->setIndent(true); $this->setIndentString(' '); $this->startDocument('1.0', 'UTF-8'); if($prm_xsltFilePath){ $this->writePi('xml-stylesheet', 'type="text/xsl" href="'.$prm_xsltFilePath.'"'); } $this->startElement('xliff'); $this->writeAttribute('version', '1.0'); $this->startElement('file'); $this->writeAttribute('original', 'global'); $this->writeAttribute('source-language', 'es'); $this->writeAttribute('datatype', 'plaintext'); $this->writeAttribute('date', date('c')); $this->startElement('body'); } public function addPhrase($source, $target){ $this->startElement('trans-unit'); $this->writeAttribute('id', $this->_phrase_id++); $this->startElement('source'); $this->text($source); $this->endElement(); $this->startElement('target'); $this->text($target); $this->endElement(); $this->endElement(); } public function getDocument(){ $this->endElement(); $this->endElement(); $this->endElement(); $this->endDocument(); return $this->outputMemory(); } public function output(){ header('Content-type: text/xml'); echo $this->getDocument(); } } ?> Example: <?php $xliff = new XLIFFConstruct(); $xliff->addPhrase('source','target'); $xliff->addPhrase('add','añadir'); $xliff->addPhrase('open','abrir'); $xliff->addPhrase('change','cambiar'); $xliff->addPhrase('new','nuevo'); $xliff->addPhrase('save','guardar'); echo $xliff->getDocument(); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 190.76.64.212 ---- Manual Page -- http://www.php.net/manual/en/ref.xmlwriter.php Edit -- https://master.php.net/note/edit/104240 Del: integrated -- https://master.php.net/note/delete/104240/integrated Del: useless -- https://master.php.net/note/delete/104240/useless Del: bad code -- https://master.php.net/note/delete/104240/bad+code Del: spam -- https://master.php.net/note/delete/104240/spam Del: non-english -- https://master.php.net/note/delete/104240/non-english Del: in docs -- https://master.php.net/note/delete/104240/in+docs Del: other reasons-- https://master.php.net/note/delete/104240 Reject -- https://master.php.net/note/reject/104240 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180211) next »